From 92d7f2e706cecefb237ba5ca0a1b550efcaa71ae Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Mon, 29 Mar 2021 23:28:18 +0200 Subject: [PATCH 1/4] fix ide-helper:models error if model doesn't have factory --- src/Console/ModelsCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 4ee4b08..8dcbb23 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1097,7 +1097,14 @@ class ModelsCommand extends Command } $modelName = get_class($model); - $factory = get_class($modelName::factory()); + $modelBaseName = class_basename($modelName); + + $factory = "\Database\Factories\\{$modelBaseName}Factory"; + + if ($modelName::newFactory()) { + $factory = get_class($modelName::newFactory()); + } + $factory = '\\' . trim($factory, '\\'); if (!class_exists($factory)) { From b19b1d69ba6efaf82ff14ec44dc5774b986256e6 Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Wed, 31 Mar 2021 23:03:55 +0200 Subject: [PATCH 2/4] testing --- .../Factories/Models/ModelWithoutFactory.php | 13 +++++ .../Console/ModelsCommand/Factories/Test.php | 19 +++++++ ...hpdoc_for_model_doesnt_have_factory__1.php | 56 +++++++++++++++++++ .../Factories/__snapshots__/Test__test__1.php | 21 +++++++ 4 files changed, 109 insertions(+) create mode 100644 tests/Console/ModelsCommand/Factories/Models/ModelWithoutFactory.php create mode 100644 tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php diff --git a/tests/Console/ModelsCommand/Factories/Models/ModelWithoutFactory.php b/tests/Console/ModelsCommand/Factories/Models/ModelWithoutFactory.php new file mode 100644 index 0000000..d88ca6b --- /dev/null +++ b/tests/Console/ModelsCommand/Factories/Models/ModelWithoutFactory.php @@ -0,0 +1,13 @@ +assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } + + /** @test */ + public function it_doesnt_generate_phpdoc_for_model_doesnt_have_factory() + { + if (!version_compare(Application::VERSION, '8.2', '>=')) { + $this->markTestSkipped( + 'This test only works in Laravel >= 8.2' + ); + } + + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertStringNotContainsString('not found', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } } diff --git a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php new file mode 100644 index 0000000..4d8b0f8 --- /dev/null +++ b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php @@ -0,0 +1,56 @@ + Date: Wed, 31 Mar 2021 23:10:46 +0200 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d85e760..78d54fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Model hooks for adding custom information from external sources to model classes through the ModelsCommand [\#945 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/945) ### Fixed +- Fix ide-helper:models exception if model doesn't have factory [\#1196 / ahmed-aliraqi](https://github.com/barryvdh/laravel-ide-helper/pull/1196) - Running tests triggering post_migrate hooks [\#1193 / netpok](https://github.com/barryvdh/laravel-ide-helper/pull/1193) - Array_merge error when config is cached prior to package install [\#1184 / netpok](https://github.com/barryvdh/laravel-ide-helper/pull/1184) From f0f7051012d302acf4a4e1ec1bda6cfd759ceff7 Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Thu, 1 Apr 2021 10:57:05 +0200 Subject: [PATCH 4/4] formatting --- .../Console/ModelsCommand/Factories/Test.php | 18 ------ ...hpdoc_for_model_doesnt_have_factory__1.php | 56 ------------------- 2 files changed, 74 deletions(-) delete mode 100644 tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php diff --git a/tests/Console/ModelsCommand/Factories/Test.php b/tests/Console/ModelsCommand/Factories/Test.php index 52c39ff..43d9c73 100644 --- a/tests/Console/ModelsCommand/Factories/Test.php +++ b/tests/Console/ModelsCommand/Factories/Test.php @@ -26,24 +26,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesMockedSnapshot(); - } - - /** @test */ - public function it_doesnt_generate_phpdoc_for_model_doesnt_have_factory() - { - if (!version_compare(Application::VERSION, '8.2', '>=')) { - $this->markTestSkipped( - 'This test only works in Laravel >= 8.2' - ); - } - - $command = $this->app->make(ModelsCommand::class); - - $tester = $this->runCommand($command, [ - '--write' => true, - ]); - $this->assertStringNotContainsString('not found', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } diff --git a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php deleted file mode 100644 index 4d8b0f8..0000000 --- a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__it_doesnt_generate_phpdoc_for_model_doesnt_have_factory__1.php +++ /dev/null @@ -1,56 +0,0 @@ -