From c8b3b3478da10de4fb688e7c140bb3b54ff12f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 23 Apr 2018 17:55:09 +0100 Subject: [PATCH 1/2] Fix files misconfiguration When the user is configuring the files to collect, omitting the `files` setting could result in a dump autoload failure due to the `composer.json` and `composer.lock` wrongly ingored. Closes #154. --- src/Configuration.php | 2 +- tests/ConfigurationFileTest.php | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index 918401c2a..5d3595b33 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -622,7 +622,7 @@ private static function retrieveFiles(stdClass $raw, string $key, string $basePa } if (false === isset($raw->{$key})) { - return []; + return $files; } $files = array_merge((array) $raw->{$key}, $files); diff --git a/tests/ConfigurationFileTest.php b/tests/ConfigurationFileTest.php index bb20c3f4c..54eeb0487 100644 --- a/tests/ConfigurationFileTest.php +++ b/tests/ConfigurationFileTest.php @@ -19,6 +19,7 @@ use KevinGH\Box\Compactor\Php; use KevinGH\Box\Json\JsonValidationException; use const DIRECTORY_SEPARATOR; +use function file_put_contents; use function KevinGH\Box\FileSystem\dump_file; use function KevinGH\Box\FileSystem\make_path_absolute; use function KevinGH\Box\FileSystem\rename; @@ -1445,6 +1446,59 @@ public function test_the_finder_config_cannot_include_invalid_methods(): void } } + public function test_the_composer_json_and_lock_files_are_always_included_even_when_the_user_configure_which_files_to_pick(): void + { + touch('file0'); + touch('file1'); + + mkdir('B'); + touch('B/fileB0'); + touch('B/fileB1'); + + file_put_contents('composer.json', '{}'); + file_put_contents('composer.lock', '{}'); + + $this->setConfig([ + 'files' => [ + 'file0', + 'file1', + ], + 'directories' => ['B'], + ]); + + // Relative to the current working directory for readability + $expected = [ + 'B/fileB0', + 'B/fileB1', + 'composer.json', + 'composer.lock', + 'file0', + 'file1', + ]; + + $actual = $this->normalizeConfigPaths($this->config->getFiles()); + + $this->assertSame($expected, $actual); + $this->assertCount(0, $this->config->getBinaryFiles()); + + $this->setConfig([ + 'directories' => ['B'], + ]); + + // Relative to the current working directory for readability + $expected = [ + 'B/fileB0', + 'B/fileB1', + 'composer.json', + 'composer.lock', + ]; + + $actual = $this->normalizeConfigPaths($this->config->getFiles()); + + $this->assertSame($expected, $actual); + $this->assertCount(0, $this->config->getBinaryFiles()); + } + public function provideJsonValidNonStringArray(): Generator { foreach ($this->provideJsonPrimitives() as $key => $values) { From 3938ce3b4ea5a70592ec5ce1dd702a88886e3c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 23 Apr 2018 18:11:47 +0100 Subject: [PATCH 2/2] Fix tests --- src/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Configuration.php b/src/Configuration.php index 5d3595b33..efda0159a 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -726,7 +726,7 @@ private static function retrieveFilesAggregate(iterable ...$fileIterators): arra foreach ($fileIterators as $fileIterator) { foreach ($fileIterator as $file) { - $files[$file->getPathname()] = $file; + $files[(string) $file] = $file; } }