From 88f3111fde4bf5874723959ce0966ad4abdf0cd5 Mon Sep 17 00:00:00 2001 From: insolita Date: Thu, 15 Apr 2021 07:08:02 +0800 Subject: [PATCH] fix #34 --- Lib/Config.php | 6 +++--- tests/ConfigTest.php | 19 +++++++++++++++++++ tests/scanner_test_config_dev.php | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/ConfigTest.php diff --git a/Lib/Config.php b/Lib/Config.php index c35d1f5..a01defb 100644 --- a/Lib/Config.php +++ b/Lib/Config.php @@ -35,9 +35,9 @@ public function __construct(string $composerJsonPath, string $vendorPath, array } $this->composerJsonPath = $composerJsonPath; $this->vendorPath = realpath(rtrim($vendorPath, DIRECTORY_SEPARATOR)) . DIRECTORY_SEPARATOR; - $this->scanDirectories = array_map(static function ($path) { - return realpath(rtrim($path, DIRECTORY_SEPARATOR)) . DIRECTORY_SEPARATOR; - }, $scanDirectories); + $this->scanDirectories = array_filter(array_map(static function ($path) { + return realpath(rtrim($path, DIRECTORY_SEPARATOR). DIRECTORY_SEPARATOR); + }, $scanDirectories)); } public function getComposerJsonPath(): string diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php new file mode 100644 index 0000000..0a7832b --- /dev/null +++ b/tests/ConfigTest.php @@ -0,0 +1,19 @@ +getScanDirectories(); + $this->assertContains(__DIR__.'/stubs/', $dirs); + $this->assertNotContains(__DIR__.'/not_existed/', $dirs); + $this->assertNotContains(__DIR__.'/missing/', $dirs); + } +} \ No newline at end of file diff --git a/tests/scanner_test_config_dev.php b/tests/scanner_test_config_dev.php index 09c6c5a..3dffc42 100644 --- a/tests/scanner_test_config_dev.php +++ b/tests/scanner_test_config_dev.php @@ -3,6 +3,6 @@ return [ 'composerJsonPath' => $projectPath . '/stub_composer.json', 'vendorPath' => $projectPath . '/../vendor/', - 'scanDirectories' => [$projectPath . '/stubs/'], + 'scanDirectories' => [$projectPath . '/stubs/', $projectPath.'/not_existed/', $projectPath.'/missing'], 'requireDev' => true ];