Skip to content

Commit

Permalink
Some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 15, 2024
1 parent 367e5a7 commit eae4576
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@

abstract class Translation extends Model
{
protected $fillable = [
'aa'
];
}
5 changes: 3 additions & 2 deletions tests/Fixtures/Models/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class TestModel extends Model

protected $fillable = [
'key',
'title',
'description',
//'title',
//'description',
];

/** @deprecated */
public function translatable(): array
{
return [
Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/Models/TestModelTranslation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Models;

use LaravelLang\Models\Translation;

class TestModelTranslation extends Translation
{
protected $fillable = [
'title',
'description',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
->toContain('TestModel')
->toContain('@property string $title')
->toContain('@property string $description')
->not->toContain('@property string $key');
->not->toContain('@property string $key')
->not->toContain('Translation');
});
44 changes: 44 additions & 0 deletions tests/Unit/Console/ModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

use DragonCode\Support\Facades\Filesystem\Directory;
use LaravelLang\Models\Console\ModelsHelperCommand;

use function Pest\Laravel\artisan;

beforeEach(fn () => Directory::ensureDelete([
base_path('app/Models/Test.php'),
base_path('app/Models/TestTranslation.php'),
]));

test('generation', function () {
$path = base_path('app/Models/TestTranslation.php');

expect($path)->not->toBeReadableFile();

artisan(ModelsHelperCommand::class, [
'name' => 'Test',
])->run();

artisan(ModelGenerator::class, [
'model' => 'App\Models\Test',
'columns' => ['test', 'description'],
])->run();

expect($path)->toBeReadableFile();

expect(file_get_contents($path))
->toContain('App\Models')
->toContain('TestTranslation')
->toContain('class TestTranslation extends Translation')
->toContain(
<<<TEXT
protected \$fillable = [
'locale',
'title',
'description',
];
TEXT
);
});

0 comments on commit eae4576

Please sign in to comment.