diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dc6410..231ae2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. -------------- ### Fixed +- Fix return value of query scopes from parent class [#1366 / sforward](https://github.com/barryvdh/laravel-ide-helper/pull/1366) ### Changed diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 5285fb0..fd6c72b 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -616,7 +616,7 @@ class ModelsCommand extends Command $this->setProperty($name, null, null, true, $comment); } } elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes') { - //Magic setAttribute + //Magic scopeAttribute $name = Str::camel(substr($method, 5)); if (!empty($name)) { $comment = $this->getCommentFromDocBlock($reflection); @@ -628,8 +628,8 @@ class ModelsCommand extends Command get_class($model->newModelQuery()) ); $modelName = $this->getClassNameInDestinationFile( - $reflection->getDeclaringClass(), - $reflection->getDeclaringClass()->getName() + new \ReflectionClass($model), + get_class($model) ); $this->setMethod($name, $builder . '|' . $modelName, $args, $comment); } diff --git a/tests/Console/ModelsCommand/QueryScopes/Models/Post.php b/tests/Console/ModelsCommand/QueryScopes/Models/Post.php new file mode 100644 index 0000000..9d64941 --- /dev/null +++ b/tests/Console/ModelsCommand/QueryScopes/Models/Post.php @@ -0,0 +1,13 @@ +app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..515dcf8 --- /dev/null +++ b/tests/Console/ModelsCommand/QueryScopes/__snapshots__/Test__test__1.php @@ -0,0 +1,189 @@ +