1
0
Fork 0

Treat empty paths in autoloader as ".", fixes #1727

pull/1781/head
Jordi Boggiano 2013-04-07 11:34:58 +02:00
parent ef65b63288
commit 3ce71466f1
2 changed files with 61 additions and 6 deletions

View File

@ -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;
}
}
}
}

View File

@ -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', '<?php namespace Foo; class Bar {}');
file_put_contents($this->workingDir.'/class.php', '<?php namespace Classmap; class Foo {}');
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_15');
$expectedNamespace = <<<'EOF'
<?php
// autoload_namespaces.php generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Foo' => $baseDir . '/',
);
EOF;
$expectedClassmap = <<<'EOF'
<?php
// autoload_classmap.php generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Classmap\\Foo' => $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';