From 15d78e6ad189a6a5f84281e37cc783a25eb49044 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 2 Feb 2012 16:38:48 +0100 Subject: [PATCH] Fix autoload generator with vendor-dir = working-dir --- src/Composer/Autoload/AutoloadGenerator.php | 7 ++++++- .../Test/Autoload/AutoloadGeneratorTest.php | 13 +++++++++++-- .../Test/Autoload/Fixtures/autoload_main3.php | 10 ++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_main3.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 78eb09f2f..f58b427b1 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -93,7 +93,12 @@ EOF; $path = strtr($path, '\\', '/'); $baseDir = ''; if (!$filesystem->isAbsolutePath($path)) { - if (strpos($path, $relVendorPath) === 0) { + // vendor dir == working dir + if (preg_match('{^(\./?)?$}', $relVendorPath)) { + $path = '/'.$path; + $baseDir = '$vendorDir . '; + } elseif (strpos($path, $relVendorPath) === 0) { + // path starts with vendor dir $path = substr($path, strlen($relVendorPath)); $baseDir = '$vendorDir . '; } else { diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index d444e5dfa..329615240 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -79,8 +79,17 @@ class AutoloadGeneratorTest extends \PHPUnit_Framework_TestCase public function testVendorDirSameAsWorkingDir() { - chdir($this->vendorDir); - $this->testMainPackageAutoloading(); + $this->vendorDir = $this->workingDir; + + $package = new MemoryPackage('a', '1.0', '1.0'); + $package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/'))); + + $this->repo->expects($this->once()) + ->method('getPackages') + ->will($this->returnValue(array())); + + $this->generator->dump($this->repo, $package, $this->im, $this->vendorDir.'/.composer'); + $this->assertAutoloadFiles('main3', $this->vendorDir.'/.composer'); } public function testMainPackageAutoloadingAlternativeVendorDir() diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php b/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php new file mode 100644 index 000000000..6f12b3d75 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_main3.php @@ -0,0 +1,10 @@ + $vendorDir . '/src/', + 'Lala' => $vendorDir . '/src/', +);