Treat empty paths in autoloader as ".", fixes #1727
parent
ef65b63288
commit
3ce71466f1
|
@ -483,7 +483,11 @@ FOOTER;
|
||||||
$path = $package->getTargetDir() . '/' . $path;
|
$path = $package->getTargetDir() . '/' . $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
$autoloads[$namespace][] = empty($installPath) ? $path : $installPath.'/'.$path;
|
if (empty($installPath)) {
|
||||||
|
$autoloads[$namespace][] = empty($path) ? '.' : $path;
|
||||||
|
} else {
|
||||||
|
$autoloads[$namespace][] = $installPath.'/'.$path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -758,14 +758,14 @@ EOF;
|
||||||
|
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
$package->setAutoload(array(
|
$package->setAutoload(array(
|
||||||
'psr-0' => array('Foo' => '../path/../src'),
|
'psr-0' => array('Foo' => '../path/../src'),
|
||||||
'classmap' => array('../classmap'),
|
'classmap' => array('../classmap'),
|
||||||
'files' => array('../test.php'),
|
'files' => array('../test.php'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->repository->expects($this->once())
|
$this->repository->expects($this->once())
|
||||||
->method('getPackages')
|
->method('getPackages')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
|
||||||
$this->fs->ensureDirectoryExists($this->workingDir.'/classmap');
|
$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'));
|
$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')
|
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
|
||||||
{
|
{
|
||||||
$a = __DIR__.'/Fixtures/autoload_'.$name.'.php';
|
$a = __DIR__.'/Fixtures/autoload_'.$name.'.php';
|
||||||
|
|
Loading…
Reference in New Issue