From 1044f466e981b0d01dda49cc93b89c9a1fdb5baf Mon Sep 17 00:00:00 2001 From: Isaac Earl Date: Sun, 20 Sep 2020 16:06:24 -0400 Subject: [PATCH] allow model_locations to have glob patterns (#1059) * allow model_locations to have glob patterns This if statement check for a valid directory was happening to early. It was checking the string that contained the wildcards to see if it is a valid directory and always failing. Need to check after the foreach starts. fixes #1058 . * test(#1059) Allow glob directories * Fix tests to chdir() into where to expect the glob to work * Update CHANGELOG.md Co-authored-by: Markus Podar --- CHANGELOG.md | 1 + src/Console/ModelsCommand.php | 11 +- .../Services/Post/Models/Post.php | 11 ++ .../ModelsCommand/AllowGlobDirectory/Test.php | 44 +++++ .../__snapshots__/Test__test__1.php | 165 ++++++++++++++++++ 5 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 tests/Console/ModelsCommand/AllowGlobDirectory/Services/Post/Models/Post.php create mode 100644 tests/Console/ModelsCommand/AllowGlobDirectory/Test.php create mode 100644 tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b77e3f8..14db60d 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 40c32ed..fad4107 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -305,13 +305,14 @@ class ModelsCommand extends Command $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 0000000..61d0d02 --- /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 0000000..c34f0a8 --- /dev/null +++ b/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php @@ -0,0 +1,165 @@ +