From 3ce71466f19b806348f63130dda134174b85ec87 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 7 Apr 2013 11:34:58 +0200 Subject: [PATCH] Treat empty paths in autoloader as ".", fixes #1727 --- src/Composer/Autoload/AutoloadGenerator.php | 6 +- .../Test/Autoload/AutoloadGeneratorTest.php | 61 +++++++++++++++++-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 69f8ecc39..427e3ead8 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -483,7 +483,11 @@ FOOTER; $path = $package->getTargetDir() . '/' . $path; } - $autoloads[$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path; + if (empty($installPath)) { + $autoloads[$namespace][] = empty($path) ? '.' : $path; + } else { + $autoloads[$namespace][] = $installPath.'/'.$path; + } } } } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 324f49d05..4aa2c32dc 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -758,14 +758,14 @@ EOF; $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array( - 'psr-0' => array('Foo' => '../path/../src'), - 'classmap' => array('../classmap'), - 'files' => array('../test.php'), + 'psr-0' => array('Foo' => '../path/../src'), + 'classmap' => array('../classmap'), + 'files' => array('../test.php'), )); $this->repository->expects($this->once()) - ->method('getPackages') - ->will($this->returnValue(array())); + ->method('getPackages') + ->will($this->returnValue(array())); $this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo'); $this->fs->ensureDirectoryExists($this->workingDir.'/classmap'); @@ -809,6 +809,57 @@ EOF; $this->assertContains("require \$baseDir . '/../test.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php')); } + public function testEmptyPaths() + { + $package = new Package('a', '1.0', '1.0'); + $package->setAutoload(array( + 'psr-0' => array('Foo' => ''), + 'classmap' => array(''), + )); + + $this->repository->expects($this->once()) + ->method('getPackages') + ->will($this->returnValue(array())); + + $this->fs->ensureDirectoryExists($this->workingDir.'/Foo'); + file_put_contents($this->workingDir.'/Foo/Bar.php', 'workingDir.'/class.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_15'); + + $expectedNamespace = <<<'EOF' + $baseDir . '/', +); + +EOF; + + $expectedClassmap = <<<'EOF' + $baseDir . '/class.php', + 'Foo\\Bar' => $baseDir . '/Foo/Bar.php', +); + +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')); + } + private function assertAutoloadFiles($name, $dir, $type = 'namespaces') { $a = __DIR__.'/Fixtures/autoload_'.$name.'.php';