Browse Source

Merge remote-tracking branch 'hason/include_paths'

Jordi Boggiano 12 years ago
parent
commit
34df3947f1

+ 4 - 3
src/Composer/Autoload/AutoloadGenerator.php

@@ -178,7 +178,7 @@ EOF;
     public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages)
     {
         // build package => install path map
-        $packageMap = array();
+        $packageMap = array(array($mainPackage, ''));
 
         foreach ($packages as $package) {
             if ($package instanceof AliasPackage) {
@@ -203,9 +203,10 @@ EOF;
      */
     public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
     {
+        $mainPackageMap = array_shift($packageMap);
         $sortedPackageMap = $this->sortPackageMap($packageMap);
-        $sortedPackageMap[] = array($mainPackage, '');
-        array_unshift($packageMap, array($mainPackage, ''));
+        $sortedPackageMap[] = $mainPackageMap;
+        array_unshift($packageMap, $mainPackageMap);
 
         $psr0 = $this->parseAutoloadsType($packageMap, 'psr-0', $mainPackage);
         $classmap = $this->parseAutoloadsType($sortedPackageMap, 'classmap', $mainPackage);

+ 28 - 0
tests/Composer/Test/Autoload/AutoloadGeneratorTest.php

@@ -524,6 +524,34 @@ EOF;
         set_include_path($oldIncludePath);
     }
 
+    public function testIncludePathsInMainPackage()
+    {
+        $package = new Package('a', '1.0', '1.0');
+        $package->setIncludePaths(array('/lib', '/src'));
+
+        $packages = array($a = new Package("a/a", "1.0", "1.0"));
+        $a->setIncludePaths(array("lib/"));
+
+        $this->repository->expects($this->once())
+            ->method("getPackages")
+            ->will($this->returnValue($packages));
+
+        mkdir($this->vendorDir."/composer", 0777, true);
+
+        $this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
+
+        $oldIncludePath = get_include_path();
+
+        require $this->vendorDir."/autoload.php";
+
+        $this->assertEquals(
+            $this->workingDir."/lib".PATH_SEPARATOR.$this->workingDir."/src".PATH_SEPARATOR.$this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
+            get_include_path()
+        );
+
+        set_include_path($oldIncludePath);
+    }
+
     public function testIncludePathFileWithoutPathsIsSkipped()
     {
         $package = new Package('a', '1.0', '1.0');