diff --git a/CHANGELOG.md b/CHANGELOG.md index b77e3f85f..14db60da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Compatibility with Lumen [\#1043 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1043) +- Allow model_locations to have glob patterns [\#1059 / saackearl](https://github.com/barryvdh/laravel-ide-helper/pull/1059) 2020-09-07, 2.8.1 ----------------- diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 40c32eddc..fad410754 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -305,13 +305,14 @@ protected function loadModels() $dir = base_path($dir); } - if (!is_dir($dir)) { - $this->error("Cannot locate directory '{'$dir}'"); - continue; - } - $dirs = glob($dir, GLOB_ONLYDIR); foreach ($dirs as $dir) { + + if (!is_dir($dir)) { + $this->error("Cannot locate directory '{'$dir}'"); + continue; + } + if (file_exists($dir)) { $classMap = ClassMapGenerator::createMap($dir); diff --git a/tests/Console/ModelsCommand/AllowGlobDirectory/Services/Post/Models/Post.php b/tests/Console/ModelsCommand/AllowGlobDirectory/Services/Post/Models/Post.php new file mode 100644 index 000000000..61d0d0276 --- /dev/null +++ b/tests/Console/ModelsCommand/AllowGlobDirectory/Services/Post/Models/Post.php @@ -0,0 +1,11 @@ +cwd = getcwd(); + } + + protected function tearDown(): void + { + chdir($this->cwd); + + parent::tearDown(); + } + + public function test(): void + { + $command = $this->app->make(ModelsCommand::class); + + chdir(__DIR__); + + $tester = $this->runCommand($command, [ + '--dir' => ['Services/*/Models'], + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php new file mode 100644 index 000000000..c34f0a879 --- /dev/null +++ b/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php @@ -0,0 +1,165 @@ +