From 5369904dd3e8af373fda1e33b065aa37da1c6e41 Mon Sep 17 00:00:00 2001 From: Andreas Hennings Date: Thu, 1 Aug 2013 15:42:30 +0200 Subject: [PATCH] autoload_files.php should return an array of files, instead of directly including them. --- src/Composer/Autoload/AutoloadGenerator.php | 10 ++++++---- .../Test/Autoload/AutoloadGeneratorTest.php | 6 +++--- .../Test/Autoload/Fixtures/autoload_files.php | 6 ++++-- .../autoload_files_files_by_dependency.php | 14 ++++++++------ .../Autoload/Fixtures/autoload_files_functions.php | 12 +++++++----- .../Fixtures/autoload_files_target_dir.php | 6 ++++-- .../Fixtures/autoload_real_files_by_dependency.php | 4 +++- .../Autoload/Fixtures/autoload_real_functions.php | 4 +++- .../Autoload/Fixtures/autoload_real_target_dir.php | 4 +++- 9 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 65ea6e5bf..b32606fce 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -300,13 +300,12 @@ EOF; $filesCode = ''; $files = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($files)); foreach ($files as $functionFile) { - $filesCode .= 'require '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).";\n"; + $filesCode .= ' '.$this->getPathCode($filesystem, $basePath, $vendorPath, $functionFile).",\n"; } if (!$filesCode) { return FALSE; } - $filesCode = rtrim($filesCode); return <<assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php')); $this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php')); - $this->assertContains("require \$vendorDir . '/b/b/bootstrap.php';", file_get_contents($vendorDir.'/composer/autoload_files.php')); - $this->assertContains("require \$baseDir . '/test.php';", file_get_contents($vendorDir.'/composer/autoload_files.php')); + $this->assertContains("\n \$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); + $this->assertContains("\n \$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php')); } public function testUpLevelRelativePaths() @@ -815,7 +815,7 @@ EOF; $this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php')); $this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php')); - $this->assertContains("require \$baseDir . '/../test.php';", file_get_contents($this->vendorDir.'/composer/autoload_files.php')); + $this->assertContains("\n \$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php')); } public function testEmptyPaths() diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files.php index 838fbb900..9ecdc0cdb 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_files.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files.php @@ -5,5 +5,7 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); -require $baseDir . '/foo.php'; -require $baseDir . '/bar.php'; \ No newline at end of file +return array( + $baseDir . '/foo.php', + $baseDir . '/bar.php', +); \ No newline at end of file diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files_files_by_dependency.php index a7763f270..eafeb2722 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_files_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files_files_by_dependency.php @@ -5,9 +5,11 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); -require $vendorDir . '/c/lorem/testC.php'; -require $vendorDir . '/z/foo/testA.php'; -require $vendorDir . '/d/d/testD.php'; -require $vendorDir . '/b/bar/testB.php'; -require $vendorDir . '/e/e/testE.php'; -require $baseDir . '/root.php'; \ No newline at end of file +return array( + $vendorDir . '/c/lorem/testC.php', + $vendorDir . '/z/foo/testA.php', + $vendorDir . '/d/d/testD.php', + $vendorDir . '/b/bar/testB.php', + $vendorDir . '/e/e/testE.php', + $baseDir . '/root.php', +); \ No newline at end of file diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php index 3d61e6b57..48058b505 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files_functions.php @@ -5,8 +5,10 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); -require $vendorDir . '/a/a/test.php'; -require $vendorDir . '/b/b/test2.php'; -require $vendorDir . '/c/c/foo/bar/test3.php'; -require $baseDir . '/root.php'; -require $vendorDir . '/c/c/foo/bar/test4.php'; \ No newline at end of file +return array( + $vendorDir . '/a/a/test.php', + $vendorDir . '/b/b/test2.php', + $vendorDir . '/c/c/foo/bar/test3.php', + $baseDir . '/root.php', + $vendorDir . '/c/c/foo/bar/test4.php', +); \ No newline at end of file diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_files_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_files_target_dir.php index 838fbb900..9ecdc0cdb 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_files_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_files_target_dir.php @@ -5,5 +5,7 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); -require $baseDir . '/foo.php'; -require $baseDir . '/bar.php'; \ No newline at end of file +return array( + $baseDir . '/foo.php', + $baseDir . '/bar.php', +); \ No newline at end of file diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php index 4195331a6..376f8512c 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php @@ -38,7 +38,9 @@ class ComposerAutoloaderInitFilesAutoloadOrder $loader->register(true); - require __DIR__ . '/autoload_files.php'; + foreach (require __DIR__ . '/autoload_files.php' as $file) { + require $file; + } return $loader; } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php index 729f9c7ed..3ddbc9ca9 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions.php @@ -38,7 +38,9 @@ class ComposerAutoloaderInitFilesAutoload $loader->register(true); - require __DIR__ . '/autoload_files.php'; + foreach (require __DIR__ . '/autoload_files.php' as $file) { + require $file; + } return $loader; } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php index 95212ef0a..347454fc5 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_target_dir.php @@ -40,7 +40,9 @@ class ComposerAutoloaderInitTargetDir $loader->register(true); - require __DIR__ . '/autoload_files.php'; + foreach (require __DIR__ . '/autoload_files.php' as $file) { + require $file; + } return $loader; }