From ebf55e287525436b904e2e3c5f2375186b48a7b7 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 25 Nov 2024 19:47:57 +0600 Subject: [PATCH 1/8] feat: skip generation for invalid stubs refs: https://github.com/RonasIT/laravel-entity-generator/issues/93 --- src/Generators/AbstractTestsGenerator.php | 21 ++++-- src/Generators/ControllerGenerator.php | 10 ++- src/Generators/EntityGenerator.php | 20 ++++++ src/Generators/FactoryGenerator.php | 54 ++++++++------- src/Generators/MigrationGenerator.php | 4 ++ src/Generators/ModelGenerator.php | 10 +-- src/Generators/NovaResourceGenerator.php | 4 ++ src/Generators/NovaTestGenerator.php | 4 ++ src/Generators/RepositoryGenerator.php | 4 ++ src/Generators/RequestsGenerator.php | 4 ++ src/Generators/ResourceGenerator.php | 8 ++- src/Generators/SeederGenerator.php | 35 ++++------ src/Generators/ServiceGenerator.php | 4 ++ src/Generators/TestsGenerator.php | 4 ++ src/Generators/TranslationsGenerator.php | 4 +- tests/ControllerGeneratorTest.php | 65 +++++++++++++++++++ tests/NovaResourceGeneratorTest.php | 24 +++++++ tests/NovaTestGeneratorTest.php | 55 ++++++++++++++++ tests/SeederGeneratorTest.php | 34 +++++++++- .../ControllerGeneratorTest/empty_api.php | 1 + 20 files changed, 305 insertions(+), 64 deletions(-) create mode 100644 tests/fixtures/ControllerGeneratorTest/empty_api.php diff --git a/src/Generators/AbstractTestsGenerator.php b/src/Generators/AbstractTestsGenerator.php index 780f889d..84263152 100644 --- a/src/Generators/AbstractTestsGenerator.php +++ b/src/Generators/AbstractTestsGenerator.php @@ -45,15 +45,15 @@ protected function getFixturesPath($fileName = null): string protected function createDump(): void { + if (!$this->checkStubExists('dump')) { + return; + } + $content = $this->getStub('dump', [ 'inserts' => $this->getInserts() ]); - $fixturePath = $this->getFixturesPath(); - - if (!file_exists($fixturePath)) { - mkdir($fixturePath, 0777, true); - } + $this->createFixtureFolder(); $dumpName = $this->getDumpName(); @@ -194,6 +194,8 @@ protected function generateFixtures(): void $object = $this->getFixtureValuesList($this->model); $entity = Str::snake($this->model); + $this->createFixtureFolder(); + foreach (self::FIXTURE_TYPES as $type => $modifications) { if ($this->isFixtureNeeded($type)) { foreach ($modifications as $modification) { @@ -273,6 +275,15 @@ protected function canGenerateUserData(): bool && $this->isMethodExists('User', 'getFields'); } + protected function createFixtureFolder(): void + { + $fixturePath = $this->getFixturesPath(); + + if (!file_exists($fixturePath)) { + mkdir($fixturePath, 0777, true); + } + } + abstract protected function getTestClassName(): string; abstract protected function isFixtureNeeded($type): bool; diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 13ddd026..57bd3dec 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -28,6 +28,10 @@ public function generate(): void ); } + if (!$this->checkStubExists('controller')) { + return; + } + $controllerContent = $this->getControllerContent($this->model); $this->saveClass('controllers', "{$this->model}Controller", $controllerContent); @@ -61,8 +65,10 @@ protected function createRoutes(): void ); } - $this->addUseController($routesPath); - $this->addRoutes($routesPath); + if ($this->checkStubExists('routes') && $this->checkStubExists('use_routes')) { + $this->addUseController($routesPath); + $this->addRoutes($routesPath); + } } protected function addRoutes($routesPath): string diff --git a/src/Generators/EntityGenerator.php b/src/Generators/EntityGenerator.php index 7d62c35a..5b83cbcc 100644 --- a/src/Generators/EntityGenerator.php +++ b/src/Generators/EntityGenerator.php @@ -5,6 +5,7 @@ use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use RonasIT\Support\Events\WarningEvent; /** * @property Filesystem $fs @@ -141,6 +142,25 @@ protected function getStub($stub, $data = []): string return view($stubPath)->with($data)->render(); } + protected function checkStubExists(string $stub): bool + { + $config = "entity-generator.stubs.{$stub}"; + + $stubPath = config($config); + + if (!view()->exists($stubPath)) { + $generationType = Str::replace('_', ' ', $stub); + + $message = "Generation of {$generationType} has been skipped cause the view {$stubPath} from the config {$config} is not exists. Please check that config has the correct view name value."; + + event(new WarningEvent($message)); + + return false; + } + + return true; + } + protected function getTableName($entityName, $delimiter = '_'): string { $entityName = Str::snake($entityName, $delimiter); diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index f0a9b6a4..b2c80d01 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -57,40 +57,46 @@ protected function generateSeparateClass(): string protected function generateToGenericClass(): string { - if (!file_exists($this->paths['factory'])) { - $this->prepareEmptyFactory(); - } - - if (!$this->checkExistModelFactory() && $this->checkExistRelatedModelsFactories()) { - $stubPath = config("entity-generator.stubs.legacy_factory"); + $stubPath = config("entity-generator.stubs.legacy_factory"); - $content = view($stubPath)->with([ - 'entity' => $this->model, - 'fields' => $this->prepareFields(), - 'modelsNamespace' => $this->getOrCreateNamespace('models') - ])->render(); - - $content = "\n\n" . $content; + $content = view($stubPath)->with([ + 'entity' => $this->model, + 'fields' => $this->prepareFields(), + 'modelsNamespace' => $this->getOrCreateNamespace('models') + ])->render(); - $createMessage = "Created a new Test factory for {$this->model} model in '{$this->paths['factory']}'"; + $content = "\n\n" . $content; - file_put_contents($this->paths['factory'], $content, FILE_APPEND); + file_put_contents($this->paths['factory'], $content, FILE_APPEND); - $this->prepareRelatedFactories(); - } else { - $createMessage = "Factory for {$this->model} model has already created, so new factory not necessary create."; - } + $this->prepareRelatedFactories(); - return $createMessage; + return "Created a new Test factory for {$this->model} model in '{$this->paths['factory']}'"; } public function generate(): void { - $createMessage = (version_compare(app()->version(), '8', '>=')) - ? $this->generateSeparateClass() - : $this->generateToGenericClass(); + $isActualVersion = (version_compare(app()->version(), '8', '>=')); - event(new SuccessCreateMessage($createMessage)); + if ($isActualVersion && $this->checkStubExists('factory')) { + event(new SuccessCreateMessage($this->generateSeparateClass())); + } else if (!$isActualVersion) { + if (!file_exists($this->paths['factory']) && $this->checkStubExists('legacy_empty_factory')) { + $this->prepareEmptyFactory(); + } + + if (!$this->checkExistModelFactory() && $this->checkExistRelatedModelsFactories()) { + if (!$this->checkStubExists('legacy_factory')) { + return; + } + + $createMessage = $this->generateToGenericClass(); + } else { + $createMessage = "Factory for {$this->model} model has already created, so new factory not necessary create."; + } + + event(new SuccessCreateMessage($createMessage)); + } } protected function prepareEmptyFactory(): void diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index 4e808579..247c0cb7 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -12,6 +12,10 @@ public function generate(): void { $entities = $this->getTableName($this->model); + if (!$this->checkStubExists('migration')) { + return; + } + $content = $this->getStub('migration', [ 'class' => $this->getPluralName($this->model), 'entity' => $this->model, diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index 2de0708c..732fb4c9 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -25,12 +25,14 @@ public function generate(): void ); } - $this->prepareRelatedModels(); - $modelContent = $this->getNewModelContent(); + if ($this->checkStubExists('model') && ($this->checkStubExists('relation') || empty($this->relations))) { + $this->prepareRelatedModels(); + $modelContent = $this->getNewModelContent(); - $this->saveClass('models', $this->model, $modelContent); + $this->saveClass('models', $this->model, $modelContent); - event(new SuccessCreateMessage("Created a new Model: {$this->model}")); + event(new SuccessCreateMessage("Created a new Model: {$this->model}")); + } } protected function getNewModelContent(): string diff --git a/src/Generators/NovaResourceGenerator.php b/src/Generators/NovaResourceGenerator.php index c1d68bd6..d929db0b 100644 --- a/src/Generators/NovaResourceGenerator.php +++ b/src/Generators/NovaResourceGenerator.php @@ -70,6 +70,10 @@ public function generate(): void ); } + if (!$this->checkStubExists('nova_resource')) { + return; + } + $novaFields = $this->prepareNovaFields(); $fileContent = $this->getStub('nova_resource', [ diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index eafac93b..fd39506e 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -40,6 +40,10 @@ public function generate(): void public function generateTests(): void { + if (!$this->checkStubExists('nova_test')) { + return; + } + $actions = $this->getActions(); $filters = $this->collectFilters(); diff --git a/src/Generators/RepositoryGenerator.php b/src/Generators/RepositoryGenerator.php index fc639a65..77c2b673 100644 --- a/src/Generators/RepositoryGenerator.php +++ b/src/Generators/RepositoryGenerator.php @@ -17,6 +17,10 @@ public function generate(): void ); } + if (!$this->checkStubExists('repository')) { + return; + } + $repositoryContent = $this->getStub('repository', [ 'entity' => $this->model, 'namespace' => $this->getOrCreateNamespace('repositories'), diff --git a/src/Generators/RequestsGenerator.php b/src/Generators/RequestsGenerator.php index 302f6b14..ada922cc 100644 --- a/src/Generators/RequestsGenerator.php +++ b/src/Generators/RequestsGenerator.php @@ -27,6 +27,10 @@ public function setRelations($relations) public function generate(): void { + if (!$this->checkStubExists('request')) { + return; + } + if (in_array('R', $this->crudOptions)) { $this->createRequest( self::GET_METHOD, diff --git a/src/Generators/ResourceGenerator.php b/src/Generators/ResourceGenerator.php index 4ac24cf2..b5e01948 100644 --- a/src/Generators/ResourceGenerator.php +++ b/src/Generators/ResourceGenerator.php @@ -9,8 +9,10 @@ class ResourceGenerator extends EntityGenerator { public function generate(): void { - $this->generateResource(); - $this->generateCollectionResource(); + if ($this->checkStubExists('resources')) { + $this->generateResource(); + $this->generateCollectionResource(); + } } public function generateCollectionResource(): void @@ -46,7 +48,7 @@ public function generateResource(): void ); } - $resourceContent = $this->getStub('resource', [ + $resourceContent = $this->getStub('resources', [ 'entity' => $this->model, 'namespace' => $this->getOrCreateNamespace('resources') ]); diff --git a/src/Generators/SeederGenerator.php b/src/Generators/SeederGenerator.php index d18d1c03..4e8f5385 100644 --- a/src/Generators/SeederGenerator.php +++ b/src/Generators/SeederGenerator.php @@ -22,6 +22,12 @@ public function __construct() public function generate(): void { + $entitySeeder = (version_compare(app()->version(), '8', '>=')) ? 'seeder' : 'legacy_seeder'; + + if (!$this->checkStubExists($entitySeeder) || !$this->checkStubExists('database_empty_seeder')) { + return; + } + if (!file_exists($this->seedsPath)) { mkdir($this->seedsPath); } @@ -36,27 +42,16 @@ public function generate(): void $this->createDatabaseSeeder(); } - $this->createEntitySeeder(); + $this->createEntitySeeder($entitySeeder); $this->appendSeederToList(); } protected function createDatabaseSeeder(): void { - $stubPath = config('entity-generator.stubs.database_empty_seeder'); - - //@TODO: remove after implementing https://github.com/RonasIT/laravel-entity-generator/issues/93 - if ($stubPath === 'entity-generator::database_seed_empty') { - $stubPath = 'entity-generator::database_empty_seeder'; - - $message = "You are using the deprecated value for 'entity-generator.stubs.database_empty_seeder' config. Please use 'entity-generator::database_empty_seeder'."; - - event(new WarningEvent($message)); - } - - $content = "getStub('database_empty_seeder', [ 'namespace' => $this->getOrCreateNamespace('seeders') - ])->render(); + ]); file_put_contents($this->databaseSeederPath, $content); @@ -65,18 +60,14 @@ protected function createDatabaseSeeder(): void event(new SuccessCreateMessage($createMessage)); } - protected function createEntitySeeder(): void + protected function createEntitySeeder(string $entitySeeder): void { - $seeder = (version_compare(app()->version(), '8', '>=')) ? 'seeder' : 'legacy_seeder'; - - $stubPath = config("entity-generator.stubs.{$seeder}"); - - $content = "with([ + $content = "getStub($entitySeeder, [ 'entity' => $this->model, 'relations' => $this->relations, 'namespace' => $this->getOrCreateNamespace('seeders'), - 'modelsNamespace' => $this->getOrCreateNamespace('models') - ])->render(); + 'modelsNamespace' => $this->getOrCreateNamespace('models'), + ]); $seederPath = "{$this->seedsPath}/{$this->model}Seeder.php"; diff --git a/src/Generators/ServiceGenerator.php b/src/Generators/ServiceGenerator.php index b59652b5..b2ac584f 100644 --- a/src/Generators/ServiceGenerator.php +++ b/src/Generators/ServiceGenerator.php @@ -36,6 +36,10 @@ public function generate(): void } } + if (!$this->checkStubExists($stub)) { + return; + } + $serviceContent = $this->getStub($stub, [ 'entity' => $this->model, 'fields' => $this->getFields(), diff --git a/src/Generators/TestsGenerator.php b/src/Generators/TestsGenerator.php index e4696ac0..66c4213f 100644 --- a/src/Generators/TestsGenerator.php +++ b/src/Generators/TestsGenerator.php @@ -50,6 +50,10 @@ protected function generateFixture($fixtureName, $data): void protected function generateTests(): void { + if (!$this->checkStubExists('test')) { + return; + } + $content = $this->getStub('test', [ 'entity' => $this->model, 'databaseTableName' => $this->getTableName($this->model), diff --git a/src/Generators/TranslationsGenerator.php b/src/Generators/TranslationsGenerator.php index 30b54a38..1b9f65d3 100644 --- a/src/Generators/TranslationsGenerator.php +++ b/src/Generators/TranslationsGenerator.php @@ -18,11 +18,11 @@ public function __construct() public function generate(): void { - if (!file_exists($this->translationPath)) { + if (!file_exists($this->translationPath) && $this->checkStubExists('validation')) { $this->createTranslate(); } - if ($this->isTranslationMissed('validation.exceptions.not_found')) { + if ($this->isTranslationMissed('validation.exceptions.not_found') && $this->checkStubExists('translation_not_found')) { $this->appendNotFoundException(); } } diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index a551dcf5..77bdb4aa 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -4,7 +4,9 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\View; use RonasIT\Support\Events\SuccessCreateMessage; +use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Generators\ControllerGenerator; @@ -69,6 +71,69 @@ className: FileNotFoundException::class, ->generate(); } + public function testControllerStubNotExist() + { + $this->mockFilesystem(); + + View::shouldReceive('exists') + ->with('entity-generator::controller') + ->once() + ->andReturnFalse(); + + app(ControllerGenerator::class) + ->setModel('Post') + ->setCrudOptions(['C', 'R', 'U', 'D']) + ->generate(); + + $this->assertGeneratedFileEquals('empty_api.php', 'routes/api.php'); + $this->assertFileDoesNotExist('app/Http/Controllers/PostController.php'); + + $this->assertEventPushed( + className: WarningEvent::class, + message: 'Generation of controller has been skipped cause the view entity-generator::controller from the config entity-generator.stubs.controller is not exists. Please check that config has the correct view name value.', + ); + } + + public function testRoutesStubNotExist() + { + $this->mockFilesystem(); + + config(['entity-generator.stubs.routes' => 'incorrect_stub']); + + app(ControllerGenerator::class) + ->setModel('Post') + ->setCrudOptions(['C', 'R', 'U', 'D']) + ->generate(); + + $this->assertGeneratedFileEquals('created_controller.php', 'app/Http/Controllers/PostController.php'); + $this->assertGeneratedFileEquals('empty_api.php', 'routes/api.php'); + + $this->assertEventPushedChain([ + WarningEvent::class => 'Generation of routes has been skipped cause the view incorrect_stub from the config entity-generator.stubs.routes is not exists. Please check that config has the correct view name value.', + SuccessCreateMessage::class => 'Created a new Controller: PostController', + ]); + } + + public function testUseRoutesStubNotExist() + { + $this->mockFilesystem(); + + config(['entity-generator.stubs.use_routes' => 'incorrect_stub']); + + app(ControllerGenerator::class) + ->setModel('Post') + ->setCrudOptions(['C', 'R', 'U', 'D']) + ->generate(); + + $this->assertGeneratedFileEquals('created_controller.php', 'app/Http/Controllers/PostController.php'); + $this->assertGeneratedFileEquals('empty_api.php', 'routes/api.php'); + + $this->assertEventPushedChain([ + WarningEvent::class => 'Generation of use routes has been skipped cause the view incorrect_stub from the config entity-generator.stubs.use_routes is not exists. Please check that config has the correct view name value.', + SuccessCreateMessage::class => 'Created a new Controller: PostController', + ]); + } + public function testSuccess() { $this->mockFilesystem(); diff --git a/tests/NovaResourceGeneratorTest.php b/tests/NovaResourceGeneratorTest.php index 95be8b76..864cf475 100644 --- a/tests/NovaResourceGeneratorTest.php +++ b/tests/NovaResourceGeneratorTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Event; use RonasIT\Support\Events\SuccessCreateMessage; +use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Generators\NovaResourceGenerator; @@ -68,6 +69,29 @@ className: ClassAlreadyExistsException::class, ->generate(); } + public function testNovaResourceStubNotExist() + { + $this->mockNovaServiceProviderExists(); + + $this->mockFilesystem(); + + $fields = $this->getJsonFixture('command_line_fields.json'); + + config(['entity-generator.stubs.nova_resource' => 'incorrect_stub']); + + app(NovaResourceGenerator::class) + ->setModel('Post') + ->setFields($fields) + ->generate(); + + $this->assertFileDoesNotExist('app/Nova/PostResource.php'); + + $this->assertEventPushed( + className: WarningEvent::class, + message: 'Generation of nova resource has been skipped cause the view incorrect_stub from the config entity-generator.stubs.nova_resource is not exists. Please check that config has the correct view name value.', + ); + } + public function testSuccess() { $this->mockNovaServiceProviderExists(); diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 3159b47e..ca257105 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Event; use RonasIT\Support\Events\SuccessCreateMessage; +use RonasIT\Support\Events\WarningEvent; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Generators\NovaTestGenerator; @@ -52,6 +53,60 @@ className: ClassAlreadyExistsException::class, ->generate(); } + public function testNovaTestStubNotExist() + { + Event::fake(); + + $this->mockNovaServiceProviderExists(); + + $this->mockFilesystem(); + $this->mockNovaRequestClassCall(); + + config(['entity-generator.stubs.nova_test' => 'incorrect_stub']); + + app(NovaTestGenerator::class) + ->setModel('WelcomeBonus') + ->generate(); + + $this->assertFileDoesNotExist('tests/NovaWelcomeBonusTest.php'); + $this->assertGeneratedFileEquals('dump.sql', 'tests/fixtures/NovaWelcomeBonusTest/nova_welcome_bonus_dump.sql'); + $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_request.json'); + $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_response.json'); + $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/update_welcome_bonus_request.json'); + + $this->assertEventPushed( + className: WarningEvent::class, + message: 'Generation of nova test has been skipped cause the view incorrect_stub from the config entity-generator.stubs.nova_test is not exists. Please check that config has the correct view name value.', + ); + } + + public function testDumpStubNotExist() + { + Event::fake(); + + $this->mockNovaServiceProviderExists(); + + $this->mockFilesystem(); + $this->mockNovaRequestClassCall(); + + config(['entity-generator.stubs.dump' => 'incorrect_stub']); + + app(NovaTestGenerator::class) + ->setModel('WelcomeBonus') + ->generate(); + + $this->assertGeneratedFileEquals('created_resource_test.php', 'tests/NovaWelcomeBonusTest.php'); + $this->assertFileDoesNotExist('tests/fixtures/NovaWelcomeBonusTest/nova_welcome_bonus_dump.sql'); + $this->assertGeneratedFileEquals('create_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_request.json'); + $this->assertGeneratedFileEquals('create_welcome_bonus_response.json', 'tests/fixtures/NovaWelcomeBonusTest/create_welcome_bonus_response.json'); + $this->assertGeneratedFileEquals('update_welcome_bonus_request.json', 'tests/fixtures/NovaWelcomeBonusTest/update_welcome_bonus_request.json'); + + $this->assertEventPushed( + className: WarningEvent::class, + message: 'Generation of dump has been skipped cause the view incorrect_stub from the config entity-generator.stubs.dump is not exists. Please check that config has the correct view name value.', + ); + } + public function testSuccess() { $this->mockNovaServiceProviderExists(); diff --git a/tests/SeederGeneratorTest.php b/tests/SeederGeneratorTest.php index 375917c5..a6d0a7bb 100644 --- a/tests/SeederGeneratorTest.php +++ b/tests/SeederGeneratorTest.php @@ -36,7 +36,7 @@ public function testCreateSeeder() $this->assertGeneratedFileEquals('post_seeder.php', 'database/seeders/PostSeeder.php'); } - public function testCreateSeederWithOldConfig() + public function testCreateSeederEmptyDatabaseSeederStubNotExist() { $this->mockFilesystem(); @@ -56,7 +56,37 @@ public function testCreateSeederWithOldConfig() $this->assertEventPushed( className: WarningEvent::class, - message: "You are using the deprecated value for 'entity-generator.stubs.database_empty_seeder' config. Please use 'entity-generator::database_empty_seeder'.", + message: 'Generation of database empty seeder has been skipped cause the view entity-generator::database_seed_empty from the config entity-generator.stubs.database_empty_seeder is not exists. Please check that config has the correct view name value.', ); + + $this->assertFileDoesNotExist("{$this->generatedFileBasePath}/database/seeders/PostSeeder.php"); + $this->assertFileDoesNotExist('database/seeders/DatabaseSeeder.php'); + } + + public function testCreateSeederEntityDatabaseSeederStubNotExist() + { + $this->mockFilesystem(); + + config([ + 'entity-generator.stubs.seeder' => 'incorrect_stub', + ]); + + app(SeederGenerator::class) + ->setRelations([ + 'hasOne' => [], + 'belongsTo' => ['User'], + 'hasMany' => ['Comment'], + 'belongsToMany' => [] + ]) + ->setModel('Post') + ->generate(); + + $this->assertEventPushed( + className: WarningEvent::class, + message: 'Generation of seeder has been skipped cause the view incorrect_stub from the config entity-generator.stubs.seeder is not exists. Please check that config has the correct view name value.', + ); + + $this->assertFileDoesNotExist("{$this->generatedFileBasePath}/database/seeders/PostSeeder.php"); + $this->assertFileDoesNotExist('database/seeders/DatabaseSeeder.php'); } } \ No newline at end of file diff --git a/tests/fixtures/ControllerGeneratorTest/empty_api.php b/tests/fixtures/ControllerGeneratorTest/empty_api.php new file mode 100644 index 00000000..a8143662 --- /dev/null +++ b/tests/fixtures/ControllerGeneratorTest/empty_api.php @@ -0,0 +1 @@ + Date: Tue, 26 Nov 2024 14:49:32 +0600 Subject: [PATCH 2/8] fix: correct stub name refs: https://github.com/RonasIT/laravel-entity-generator/issues/50 --- src/Generators/ResourceGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generators/ResourceGenerator.php b/src/Generators/ResourceGenerator.php index b5e01948..1f64d182 100644 --- a/src/Generators/ResourceGenerator.php +++ b/src/Generators/ResourceGenerator.php @@ -9,7 +9,7 @@ class ResourceGenerator extends EntityGenerator { public function generate(): void { - if ($this->checkStubExists('resources')) { + if ($this->checkStubExists('resource')) { $this->generateResource(); $this->generateCollectionResource(); } @@ -48,7 +48,7 @@ public function generateResource(): void ); } - $resourceContent = $this->getStub('resources', [ + $resourceContent = $this->getStub('resource', [ 'entity' => $this->model, 'namespace' => $this->getOrCreateNamespace('resources') ]); From c9dc6f667a6d28c7d1d68f41b98524277091ef09 Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 26 Nov 2024 15:44:48 +0600 Subject: [PATCH 3/8] fix: correct message refs: https://github.com/RonasIT/laravel-entity-generator/issues/50 --- src/Generators/ControllerGenerator.php | 2 +- src/Generators/FactoryGenerator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 57bd3dec..55fa5957 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -23,7 +23,7 @@ public function generate(): void if (!$this->classExists('services', "{$this->model}Service")) { $this->throwFailureException( ClassNotExistsException::class, - "Cannot create {$this->model}Service cause {$this->model}Service does not exists.", + "Cannot create {$this->model}Controller cause {$this->model}Service does not exists.", "Create a {$this->model}Service by himself.", ); } diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index b2c80d01..320cf7ac 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -76,7 +76,7 @@ protected function generateToGenericClass(): string public function generate(): void { - $isActualVersion = (version_compare(app()->version(), '8', '>=')); + $isActualVersion = version_compare(app()->version(), '8', '>='); if ($isActualVersion && $this->checkStubExists('factory')) { event(new SuccessCreateMessage($this->generateSeparateClass())); From 356facf180d7d5c8734edb85810af18a21bad1b8 Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 26 Nov 2024 17:10:31 +0600 Subject: [PATCH 4/8] fix: generate collection resource refs: https://github.com/RonasIT/laravel-entity-generator/issues/50 --- src/Generators/ResourceGenerator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Generators/ResourceGenerator.php b/src/Generators/ResourceGenerator.php index 1f64d182..7a084a84 100644 --- a/src/Generators/ResourceGenerator.php +++ b/src/Generators/ResourceGenerator.php @@ -11,7 +11,10 @@ public function generate(): void { if ($this->checkStubExists('resource')) { $this->generateResource(); - $this->generateCollectionResource(); + + if ($this->checkStubExists('collection_resource')) { + $this->generateCollectionResource(); + } } } From ed400f47e82e8dbaae2e29122028d9f8748ce1aa Mon Sep 17 00:00:00 2001 From: roman Date: Tue, 26 Nov 2024 17:40:39 +0600 Subject: [PATCH 5/8] fix: test refs: https://github.com/RonasIT/laravel-entity-generator/issues/50 --- tests/ControllerGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ControllerGeneratorTest.php b/tests/ControllerGeneratorTest.php index 77bdb4aa..1d447e63 100644 --- a/tests/ControllerGeneratorTest.php +++ b/tests/ControllerGeneratorTest.php @@ -48,7 +48,7 @@ public function testModelServiceNotExists() $this->assertExceptionThrowed( className: ClassNotExistsException::class, - message: 'Cannot create PostService cause PostService does not exists. Create a PostService by himself.', + message: 'Cannot create PostController cause PostService does not exists. Create a PostService by himself.', ); app(ControllerGenerator::class) From 4d4fbf3a3fe795605b7d18bce66a168c566dcd18 Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 2 Dec 2024 17:25:32 +0600 Subject: [PATCH 6/8] refactor: code refs: https://github.com/RonasIT/laravel-entity-generator/issues/108 --- config/entity-generator.php | 9 ++--- src/Generators/AbstractTestsGenerator.php | 2 +- src/Generators/ControllerGenerator.php | 4 +-- src/Generators/EntityGenerator.php | 6 ++-- src/Generators/FactoryGenerator.php | 6 ++-- src/Generators/MigrationGenerator.php | 2 +- src/Generators/ModelGenerator.php | 2 +- src/Generators/NovaResourceGenerator.php | 2 +- src/Generators/NovaTestGenerator.php | 2 +- src/Generators/RepositoryGenerator.php | 2 +- src/Generators/RequestsGenerator.php | 2 +- src/Generators/ResourceGenerator.php | 4 +-- src/Generators/SeederGenerator.php | 10 +++--- src/Generators/ServiceGenerator.php | 2 +- src/Generators/TestsGenerator.php | 2 +- src/Generators/TranslationsGenerator.php | 4 +-- stubs/legacy_seeder.blade.php | 44 ----------------------- tests/SeederGeneratorTest.php | 8 ++--- 18 files changed, 29 insertions(+), 84 deletions(-) delete mode 100644 stubs/legacy_seeder.blade.php diff --git a/config/entity-generator.php b/config/entity-generator.php index bff879b1..021fa993 100644 --- a/config/entity-generator.php +++ b/config/entity-generator.php @@ -7,12 +7,8 @@ 'requests' => 'app/Http/Requests', 'controllers' => 'app/Http/Controllers', 'migrations' => 'database/migrations', - 'seeders' => (version_compare(app()->version(), '8', '>=')) - ? 'database/seeders' - : 'database/seeds', - 'database_seeder' => (version_compare(app()->version(), '8', '>=')) - ? 'database/seeders/DatabaseSeeder.php' - : 'database/seeds/DatabaseSeeder.php', + 'seeders' => 'database/seeders', + 'database_seeder' => 'database/seeders/DatabaseSeeder.php', 'repositories' => 'app/Repositories', 'tests' => 'tests', 'routes' => 'routes/api.php', @@ -35,7 +31,6 @@ 'legacy_factory' => 'entity-generator::legacy_factory', 'legacy_empty_factory' => 'entity-generator::legacy_empty_factory', 'seeder' => 'entity-generator::seeder', - 'legacy_seeder' => 'entity-generator::legacy_seeder', 'database_empty_seeder' => 'entity-generator::database_empty_seeder', 'migration' => 'entity-generator::migration', 'dump' => 'entity-generator::dumps.pgsql', diff --git a/src/Generators/AbstractTestsGenerator.php b/src/Generators/AbstractTestsGenerator.php index 84263152..fab6af5c 100644 --- a/src/Generators/AbstractTestsGenerator.php +++ b/src/Generators/AbstractTestsGenerator.php @@ -45,7 +45,7 @@ protected function getFixturesPath($fileName = null): string protected function createDump(): void { - if (!$this->checkStubExists('dump')) { + if (!$this->isStubExists('dump')) { return; } diff --git a/src/Generators/ControllerGenerator.php b/src/Generators/ControllerGenerator.php index 55fa5957..a114080c 100644 --- a/src/Generators/ControllerGenerator.php +++ b/src/Generators/ControllerGenerator.php @@ -28,7 +28,7 @@ public function generate(): void ); } - if (!$this->checkStubExists('controller')) { + if (!$this->isStubExists('controller')) { return; } @@ -65,7 +65,7 @@ protected function createRoutes(): void ); } - if ($this->checkStubExists('routes') && $this->checkStubExists('use_routes')) { + if ($this->isStubExists('routes') && $this->isStubExists('use_routes')) { $this->addUseController($routesPath); $this->addRoutes($routesPath); } diff --git a/src/Generators/EntityGenerator.php b/src/Generators/EntityGenerator.php index 5b83cbcc..74a4b4a7 100644 --- a/src/Generators/EntityGenerator.php +++ b/src/Generators/EntityGenerator.php @@ -142,14 +142,14 @@ protected function getStub($stub, $data = []): string return view($stubPath)->with($data)->render(); } - protected function checkStubExists(string $stub): bool + protected function isStubExists(string $stubName): bool { - $config = "entity-generator.stubs.{$stub}"; + $config = "entity-generator.stubs.{$stubName}"; $stubPath = config($config); if (!view()->exists($stubPath)) { - $generationType = Str::replace('_', ' ', $stub); + $generationType = Str::replace('_', ' ', $stubName); $message = "Generation of {$generationType} has been skipped cause the view {$stubPath} from the config {$config} is not exists. Please check that config has the correct view name value."; diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 320cf7ac..2f0dc71d 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -78,15 +78,15 @@ public function generate(): void { $isActualVersion = version_compare(app()->version(), '8', '>='); - if ($isActualVersion && $this->checkStubExists('factory')) { + if ($isActualVersion && $this->isStubExists('factory')) { event(new SuccessCreateMessage($this->generateSeparateClass())); } else if (!$isActualVersion) { - if (!file_exists($this->paths['factory']) && $this->checkStubExists('legacy_empty_factory')) { + if (!file_exists($this->paths['factory']) && $this->isStubExists('legacy_empty_factory')) { $this->prepareEmptyFactory(); } if (!$this->checkExistModelFactory() && $this->checkExistRelatedModelsFactories()) { - if (!$this->checkStubExists('legacy_factory')) { + if (!$this->isStubExists('legacy_factory')) { return; } diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index 247c0cb7..d43026db 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -12,7 +12,7 @@ public function generate(): void { $entities = $this->getTableName($this->model); - if (!$this->checkStubExists('migration')) { + if (!$this->isStubExists('migration')) { return; } diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php index 732fb4c9..e113a386 100644 --- a/src/Generators/ModelGenerator.php +++ b/src/Generators/ModelGenerator.php @@ -25,7 +25,7 @@ public function generate(): void ); } - if ($this->checkStubExists('model') && ($this->checkStubExists('relation') || empty($this->relations))) { + if ($this->isStubExists('model') && ($this->isStubExists('relation') || empty($this->relations))) { $this->prepareRelatedModels(); $modelContent = $this->getNewModelContent(); diff --git a/src/Generators/NovaResourceGenerator.php b/src/Generators/NovaResourceGenerator.php index d929db0b..ae6a0616 100644 --- a/src/Generators/NovaResourceGenerator.php +++ b/src/Generators/NovaResourceGenerator.php @@ -70,7 +70,7 @@ public function generate(): void ); } - if (!$this->checkStubExists('nova_resource')) { + if (!$this->isStubExists('nova_resource')) { return; } diff --git a/src/Generators/NovaTestGenerator.php b/src/Generators/NovaTestGenerator.php index fd39506e..080336ba 100644 --- a/src/Generators/NovaTestGenerator.php +++ b/src/Generators/NovaTestGenerator.php @@ -40,7 +40,7 @@ public function generate(): void public function generateTests(): void { - if (!$this->checkStubExists('nova_test')) { + if (!$this->isStubExists('nova_test')) { return; } diff --git a/src/Generators/RepositoryGenerator.php b/src/Generators/RepositoryGenerator.php index 77c2b673..a046397f 100644 --- a/src/Generators/RepositoryGenerator.php +++ b/src/Generators/RepositoryGenerator.php @@ -17,7 +17,7 @@ public function generate(): void ); } - if (!$this->checkStubExists('repository')) { + if (!$this->isStubExists('repository')) { return; } diff --git a/src/Generators/RequestsGenerator.php b/src/Generators/RequestsGenerator.php index ada922cc..c96e1290 100644 --- a/src/Generators/RequestsGenerator.php +++ b/src/Generators/RequestsGenerator.php @@ -27,7 +27,7 @@ public function setRelations($relations) public function generate(): void { - if (!$this->checkStubExists('request')) { + if (!$this->isStubExists('request')) { return; } diff --git a/src/Generators/ResourceGenerator.php b/src/Generators/ResourceGenerator.php index 7a084a84..b4343e25 100644 --- a/src/Generators/ResourceGenerator.php +++ b/src/Generators/ResourceGenerator.php @@ -9,10 +9,10 @@ class ResourceGenerator extends EntityGenerator { public function generate(): void { - if ($this->checkStubExists('resource')) { + if ($this->isStubExists('resource')) { $this->generateResource(); - if ($this->checkStubExists('collection_resource')) { + if ($this->isStubExists('collection_resource')) { $this->generateCollectionResource(); } } diff --git a/src/Generators/SeederGenerator.php b/src/Generators/SeederGenerator.php index 4e8f5385..5872e11f 100644 --- a/src/Generators/SeederGenerator.php +++ b/src/Generators/SeederGenerator.php @@ -22,9 +22,7 @@ public function __construct() public function generate(): void { - $entitySeeder = (version_compare(app()->version(), '8', '>=')) ? 'seeder' : 'legacy_seeder'; - - if (!$this->checkStubExists($entitySeeder) || !$this->checkStubExists('database_empty_seeder')) { + if (!$this->isStubExists('seeder') || !$this->isStubExists('database_empty_seeder')) { return; } @@ -42,7 +40,7 @@ public function generate(): void $this->createDatabaseSeeder(); } - $this->createEntitySeeder($entitySeeder); + $this->createEntitySeeder(); $this->appendSeederToList(); } @@ -60,9 +58,9 @@ protected function createDatabaseSeeder(): void event(new SuccessCreateMessage($createMessage)); } - protected function createEntitySeeder(string $entitySeeder): void + protected function createEntitySeeder(): void { - $content = "getStub($entitySeeder, [ + $content = "getStub('seeder', [ 'entity' => $this->model, 'relations' => $this->relations, 'namespace' => $this->getOrCreateNamespace('seeders'), diff --git a/src/Generators/ServiceGenerator.php b/src/Generators/ServiceGenerator.php index b2ac584f..df126329 100644 --- a/src/Generators/ServiceGenerator.php +++ b/src/Generators/ServiceGenerator.php @@ -36,7 +36,7 @@ public function generate(): void } } - if (!$this->checkStubExists($stub)) { + if (!$this->isStubExists($stub)) { return; } diff --git a/src/Generators/TestsGenerator.php b/src/Generators/TestsGenerator.php index 66c4213f..d12ac00d 100644 --- a/src/Generators/TestsGenerator.php +++ b/src/Generators/TestsGenerator.php @@ -50,7 +50,7 @@ protected function generateFixture($fixtureName, $data): void protected function generateTests(): void { - if (!$this->checkStubExists('test')) { + if (!$this->isStubExists('test')) { return; } diff --git a/src/Generators/TranslationsGenerator.php b/src/Generators/TranslationsGenerator.php index 1b9f65d3..155e37f3 100644 --- a/src/Generators/TranslationsGenerator.php +++ b/src/Generators/TranslationsGenerator.php @@ -18,11 +18,11 @@ public function __construct() public function generate(): void { - if (!file_exists($this->translationPath) && $this->checkStubExists('validation')) { + if (!file_exists($this->translationPath) && $this->isStubExists('validation')) { $this->createTranslate(); } - if ($this->isTranslationMissed('validation.exceptions.not_found') && $this->checkStubExists('translation_not_found')) { + if ($this->isTranslationMissed('validation.exceptions.not_found') && $this->isStubExists('translation_not_found')) { $this->appendNotFoundException(); } } diff --git a/stubs/legacy_seeder.blade.php b/stubs/legacy_seeder.blade.php deleted file mode 100644 index 50a5c6dc..00000000 --- a/stubs/legacy_seeder.blade.php +++ /dev/null @@ -1,44 +0,0 @@ -namespace {{$namespace}}; - -use Illuminate\Database\Seeder; - -class {{$entity}}Seeder extends Seeder -{ - public function run() - { -@if (empty($relations['belongsTo'])) -@if(empty(array_filter($relations))) - factory(\{{$modelsNamespace}}\{{$entity}}::class)->create([]); -@else - ${{strtolower($entity)}} = factory(\{{$modelsNamespace}}\{{$entity}}::class)->create([]); -@endif -@else -@if(empty(array_filter($relations))) - ${{strtolower($entity)}} = factory(\{{$modelsNamespace}}\{{$entity}}::class)->create([ -@else - factory(\{{$modelsNamespace}}\{{$entity}}::class)->create([ -@endif -@foreach($relations['belongsTo'] as $relation) - '{{strtolower($relation)}}_id' => factory(\{{$modelsNamespace}}\{{$relation}}::class)->create()->id, -@endforeach - ]); -@endif - -@foreach($relations['hasOne'] as $relation) - factory(\{{$modelsNamespace}}\{{$relation}}::class)->create([ - '{{strtolower($entity)}}_id' => ${{strtolower($entity)}}->id, - ]); - -@endforeach -@foreach($relations['hasMany'] as $relation) - factory(\{{$modelsNamespace}}\{{$relation}}::class, 10)->create()->each([ - '{{strtolower($entity)}}_id' => ${{strtolower($entity)}}->id, - ]); - -@endforeach -@foreach($relations['belongsToMany'] as $relation) - $list = factory(\{{$modelsNamespace}}\{{$relation}}::class, 10)->create()->pluck('id'); - ${{strtolower($entity)}}->{{strtolower($relation)}}s()->sync($list); -@endforeach - } -} \ No newline at end of file diff --git a/tests/SeederGeneratorTest.php b/tests/SeederGeneratorTest.php index a6d0a7bb..167b4821 100644 --- a/tests/SeederGeneratorTest.php +++ b/tests/SeederGeneratorTest.php @@ -40,9 +40,7 @@ public function testCreateSeederEmptyDatabaseSeederStubNotExist() { $this->mockFilesystem(); - config([ - 'entity-generator.stubs.database_empty_seeder' => 'entity-generator::database_seed_empty', - ]); + config(['entity-generator.stubs.database_empty_seeder' => 'entity-generator::database_seed_empty']); app(SeederGenerator::class) ->setRelations([ @@ -67,9 +65,7 @@ public function testCreateSeederEntityDatabaseSeederStubNotExist() { $this->mockFilesystem(); - config([ - 'entity-generator.stubs.seeder' => 'incorrect_stub', - ]); + config(['entity-generator.stubs.seeder' => 'incorrect_stub']); app(SeederGenerator::class) ->setRelations([ From a34c85f9fbe69890d388b596e5c2db3bcf4dbe4c Mon Sep 17 00:00:00 2001 From: roman Date: Mon, 2 Dec 2024 18:03:20 +0600 Subject: [PATCH 7/8] fix: conflicts refs: https://github.com/RonasIT/laravel-entity-generator/issues/108 --- src/Generators/FactoryGenerator.php | 7 ++++++- tests/NovaTestGeneratorTest.php | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 3cbcf4b7..fe18caf8 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -5,6 +5,7 @@ use Faker\Generator as Faker; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use InvalidArgumentException; use RonasIT\Support\Exceptions\FakerMethodNotFoundException; use RonasIT\Support\Exceptions\ClassNotExistsException; use RonasIT\Support\Exceptions\ClassAlreadyExistsException; @@ -42,6 +43,10 @@ public function generate(): void ); } + if (!$this->isStubExists('factory')) { + return; + } + $factoryContent = $this->getStub('factory', [ 'namespace' => $this->getOrCreateNamespace('factories'), 'entity' => $this->model, @@ -112,4 +117,4 @@ protected function prepareFields(): array return $result; } -} +} \ No newline at end of file diff --git a/tests/NovaTestGeneratorTest.php b/tests/NovaTestGeneratorTest.php index 6d49dd73..be1a052b 100644 --- a/tests/NovaTestGeneratorTest.php +++ b/tests/NovaTestGeneratorTest.php @@ -60,12 +60,23 @@ public function testNovaTestStubNotExist() { Event::fake(); - $this->mockNovaServiceProviderExists(); + $this->mockNativeGeneratorFunctions( + $this->nativeClassExistsMethodCall([NovaServiceProvider::class, true]), + $this->nativeClassExistsMethodCall([WelcomeBonus::class, true]), + ); $this->mockFilesystem(); $this->mockNovaRequestClassCall(); - config(['entity-generator.stubs.nova_test' => 'incorrect_stub']); + config([ + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', + 'entity-generator.stubs.nova_test' => 'incorrect_stub', + ]); + + $mock = Mockery::mock('alias:Illuminate\Support\Facades\DB'); + $mock + ->shouldReceive('beginTransaction', 'rollBack') + ->once(); app(NovaTestGenerator::class) ->setModel('WelcomeBonus') @@ -92,7 +103,10 @@ public function testDumpStubNotExist() $this->mockFilesystem(); $this->mockNovaRequestClassCall(); - config(['entity-generator.stubs.dump' => 'incorrect_stub']); + config([ + 'entity-generator.paths.models' => 'RonasIT/Support/Tests/Support/Models', + 'entity-generator.stubs.dump' => 'incorrect_stub', + ]); app(NovaTestGenerator::class) ->setModel('WelcomeBonus') From 75d359dbbe6b0492b912d385788e9004508fe550 Mon Sep 17 00:00:00 2001 From: DenTray Date: Fri, 6 Dec 2024 14:32:51 +0600 Subject: [PATCH 8/8] Update src/Generators/MigrationGenerator.php --- src/Generators/MigrationGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index d43026db..97d08e32 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -10,12 +10,12 @@ class MigrationGenerator extends EntityGenerator { public function generate(): void { - $entities = $this->getTableName($this->model); - if (!$this->isStubExists('migration')) { return; } + $entities = $this->getTableName($this->model); + $content = $this->getStub('migration', [ 'class' => $this->getPluralName($this->model), 'entity' => $this->model,