diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f709b..6066eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Fixes - Handle PHP 8.1 deprecation warnings when passing `null` to `new \ReflectionClass` [#1351 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1351) +- Fix model factory method arguments for Laravel >= 9 [#1361 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/1361) 2022-03-06, 2.12.3 ------------------ diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 3682683..963409b 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1250,7 +1250,11 @@ class ModelsCommand extends Command return; } - $this->setMethod('factory', $factory, ['...$parameters']); + if (version_compare($this->laravel->version(), '9', '>=')) { + $this->setMethod('factory', $factory, ['$count = null, $state = []']); + } else { + $this->setMethod('factory', $factory, ['...$parameters']); + } } /** diff --git a/tests/Console/ModelsCommand/Factories/Test.php b/tests/Console/ModelsCommand/Factories/Test.php index 77bd13f..1e96e34 100644 --- a/tests/Console/ModelsCommand/Factories/Test.php +++ b/tests/Console/ModelsCommand/Factories/Test.php @@ -13,11 +13,33 @@ use Illuminate\Support\Str; class Test extends AbstractModelsCommand { - public function test(): void + public function test_8(): void { - if (!version_compare(Application::VERSION, '8.2', '>=')) { + if (!version_compare(Application::VERSION, '8.2', '>=') || !version_compare(Application::VERSION, '9', '<')) { $this->markTestSkipped( - 'This test only works in Laravel >= 8.2' + 'This test only works in Laravel >= 8.2 and < 9' + ); + } + + Factory::guessFactoryNamesUsing(static::getFactoryNameResolver()); + + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertStringNotContainsString('not found', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } + + public function test_9(): void + { + if (!version_compare(Application::VERSION, '9', '>=')) { + $this->markTestSkipped( + 'This test only works in Laravel >= 9' ); } diff --git a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_8__1.php similarity index 100% rename from tests/Console/ModelsCommand/Factories/__snapshots__/Test__test__1.php rename to tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_8__1.php diff --git a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_9__1.php b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_9__1.php new file mode 100644 index 0000000..1ec977b --- /dev/null +++ b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_9__1.php @@ -0,0 +1,94 @@ +