Skip to content

Commit

Permalink
A little trick for the beta version 🙃
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 20, 2024
1 parent 288d2cb commit ac26726
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
use LaravelLang\Models\Generators\MigrationGenerator;
use LaravelLang\Models\Generators\ModelGenerator;
use LaravelLang\Models\Services\ClassMap;
use Symfony\Component\Console\Attribute\AsCommand;

use function Laravel\Prompts\info;
use function Laravel\Prompts\search;
use function Laravel\Prompts\text;

#[AsCommand(name: 'make:model:localization')]
class ModelMakeCommand extends Command
{
protected $signature = 'make:model:localization {model} {--columns=*}';
Expand Down
2 changes: 2 additions & 0 deletions src/Console/ModelsHelperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use LaravelLang\Config\Facades\Config;
use LaravelLang\Models\Generators\HelperGenerator;
use LaravelLang\Models\Services\ClassMap;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'lang:models:helper')]
class ModelsHelperCommand extends Command
{
protected $signature = 'lang:models:helper {model?}';
Expand Down
36 changes: 4 additions & 32 deletions tests/Unit/Console/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,12 @@
'description',
];
TEXT
);

expect(file_get_contents($migration))
->toContain('Schema::create(\'test_translations\'')
->toContain('Schema::dropIfExists(\'test_translations\')')
->toContain('$table->string(\'title\')->nullable()')
->toContain('$table->string(\'description\')->nullable()')
->toContain('->constrained(\'tests\')');

expect($migration)->toBeReadableFile();
expect($helper)->toBeReadableFile();
});

test('unknown model', function () {
artisan(PackageMakeModel::class, [
'model' => '\App\Models\Test',
'--columns' => ['title', 'description'],
])->run();

$model = base_path('app/Models/TestTranslation.php');
$migration = database_path('migrations/' . date('Y_m_d_His') . '_create_test_translations_table.php');
$baseMigration = database_path('migrations/' . date('Y_m_d_His') . '_create_tests_table.php');
$helper = sprintf('%s/_ide_helper_models_%s.php', Config::shared()->models->helpers, md5('App\Models\Test'));

expect(file_get_contents($model))
->toContain('App\Models')
->toContain('class TestTranslation extends Translation')
)
->toContain(
<<<TEXT
protected \$fillable = [
'locale',
'title',
'description',
protected \$casts = [
'title' => TrimCast::class,
'description' => TrimCast::class,
];
TEXT
);
Expand All @@ -97,7 +70,6 @@
->toContain('$table->string(\'description\')->nullable()')
->toContain('->constrained(\'tests\')');

expect($baseMigration)->toBeReadableFile();
expect($migration)->toBeReadableFile();
expect($helper)->toBeReadableFile();
});

0 comments on commit ac26726

Please sign in to comment.