ソースを参照

Fix autoload generator with vendor-dir = working-dir

Jordi Boggiano 13 年 前
コミット
15d78e6ad1

+ 6 - 1
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 {

+ 11 - 2
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()

+ 10 - 0
tests/Composer/Test/Autoload/Fixtures/autoload_main3.php

@@ -0,0 +1,10 @@
+<?php
+
+// autoload_namespace.php generated by Composer
+
+$vendorDir = dirname(__DIR__);
+
+return array(
+    'Main' => $vendorDir . '/src/',
+    'Lala' => $vendorDir . '/src/',
+);