From c5f3a6febde6f9e6fdcaf62e64ebee3768d0cbe9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 27 Nov 2012 14:23:10 +0100 Subject: [PATCH] Fix optimized autoloader generation for PSR-0 configs that include non-existent dirs, fixes #1286 --- src/Composer/Autoload/AutoloadGenerator.php | 3 +++ .../Test/Autoload/AutoloadGeneratorTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 9bf57b29d..5d6281cf0 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -126,6 +126,9 @@ EOF; preg_quote(rtrim($dir, '/')), strpos($namespace, '_') === false ? preg_quote(strtr($namespace, '\\', '/')) : '' ); + if (!is_dir($dir)) { + continue; + } foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) { if ('' === $namespace || 0 === strpos($class, $namespace)) { $path = '/'.$filesystem->findShortestPath(getcwd(), $path, true); diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 4192ee584..6beb39811 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -212,6 +212,24 @@ class AutoloadGeneratorTest extends TestCase $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty."); } + public function testPSR0ToClassMapIgnoresNonExistingDir() + { + $package = new Package('a', '1.0', '1.0'); + + $package->setAutoload(array('psr-0' => array('foo/bar/non/existing/'))); + + $this->repository->expects($this->once()) + ->method('getPackages') + ->will($this->returnValue(array())); + + $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8'); + $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated."); + $this->assertEquals( + array(), + include $this->vendorDir.'/composer/autoload_classmap.php' + ); + } + public function testVendorsClassMapAutoloading() { $package = new Package('a', '1.0', '1.0');