Add test and some fixes to allow absolute paths, refs #869
parent
d837b8a657
commit
a2a2f4af59
|
@ -53,7 +53,7 @@ return array(
|
|||
EOF;
|
||||
|
||||
$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getPackages());
|
||||
$autoloads = $this->parseAutoloads($packageMap);
|
||||
$autoloads = $this->parseAutoloads($packageMap, $filesystem);
|
||||
|
||||
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
||||
$exportedPaths = array();
|
||||
|
@ -118,10 +118,9 @@ EOF;
|
|||
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
||||
foreach ($autoloads['classmap'] as $dir) {
|
||||
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
|
||||
|
||||
$classmapFile .= ' '.var_export($class, true) . ' => ';
|
||||
|
||||
if (0 === strpos($path, dirname($vendorPath), 0)) {
|
||||
if (0 === strpos($path, getcwd())) {
|
||||
// this path seems to be located within this application/package
|
||||
$path = '/' . $filesystem->findShortestPath(getcwd(), $path, true);
|
||||
$classmapFile .= '$baseDir . ';
|
||||
|
@ -170,11 +169,16 @@ EOF;
|
|||
/**
|
||||
* Compiles an ordered list of namespace => path mappings
|
||||
*
|
||||
* @param array $packageMap array of array(package, installDir-relative-to-composer.json)
|
||||
* @return array array('psr-0' => array('Ns\\Foo' => array('installDir')))
|
||||
* @param array $packageMap array of array(package, installDir-relative-to-composer.json)
|
||||
* @param Filesystem $filesystem optional filesystem instance to use
|
||||
* @return array array('psr-0' => array('Ns\\Foo' => array('installDir')))
|
||||
*/
|
||||
public function parseAutoloads(array $packageMap)
|
||||
public function parseAutoloads(array $packageMap, Filesystem $filesystem = null)
|
||||
{
|
||||
if (!$filesystem) {
|
||||
$filesystem = new Filesystem;
|
||||
}
|
||||
|
||||
$autoloads = array('classmap' => array(), 'psr-0' => array(), 'files' => array());
|
||||
foreach ($packageMap as $item) {
|
||||
list($package, $installPath) = $item;
|
||||
|
@ -190,7 +194,13 @@ EOF;
|
|||
}
|
||||
foreach ($mapping as $namespace => $paths) {
|
||||
foreach ((array) $paths as $path) {
|
||||
$autoloads[$type][$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path;
|
||||
if ($filesystem->isAbsolutePath($path)) {
|
||||
// handle absolute paths in raw form
|
||||
$autoloads[$type][$namespace][] = $path;
|
||||
} else {
|
||||
// prepend install path (including target dir) to the relative paths
|
||||
$autoloads[$type][$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ class AutoloadGeneratorTest extends TestCase
|
|||
$packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0');
|
||||
$packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0');
|
||||
$a->setAutoload(array('classmap' => array('src/')));
|
||||
$b->setAutoload(array('classmap' => array('src/', 'lib/')));
|
||||
$b->setAutoload(array('classmap' => array('src/', 'lib/', __FILE__)));
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
->method('getPackages')
|
||||
|
@ -211,10 +211,12 @@ class AutoloadGeneratorTest extends TestCase
|
|||
'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php',
|
||||
'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/src/b.php',
|
||||
'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/b/b/lib/c.php',
|
||||
'Composer\Test\Autoload\AutoloadGeneratorTest' => __FILE__,
|
||||
),
|
||||
include ($this->vendorDir.'/composer/autoload_classmap.php')
|
||||
);
|
||||
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
|
||||
$expected = str_replace('%path%', var_export(__FILE__, true), file_get_contents(__DIR__.'/Fixtures/autoload_classmap4.php'));
|
||||
$this->assertEquals($expected, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
|
||||
}
|
||||
|
||||
public function testClassMapAutoloadingEmptyDirAndExactFile()
|
||||
|
|
|
@ -6,6 +6,7 @@ $vendorDir = dirname(__DIR__);
|
|||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
'Composer\\Test\\Autoload\\AutoloadGeneratorTest' => %path%,
|
||||
'ClassMapBaz' => $baseDir . '/composer-test-autoload/b/b/lib/c.php',
|
||||
'ClassMapFoo' => $baseDir . '/composer-test-autoload/a/a/src/a.php',
|
||||
'ClassMapBar' => $baseDir . '/composer-test-autoload/b/b/src/b.php',
|
||||
|
|
Loading…
Reference in New Issue