1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

[Autoload] Make all paths relative for file portability

This commit is contained in:
Martin Hasoň 2013-04-05 14:22:16 +02:00
parent 0a561d7bf1
commit 07d2f17afe
3 changed files with 87 additions and 46 deletions

View file

@ -750,6 +750,65 @@ EOF;
$this->assertContains("require \$baseDir . '/test.php';", file_get_contents($vendorDir.'/composer/autoload_real.php'));
}
public function testUpLevelRelativePaths()
{
$workingDir = $this->workingDir.'/working-dir';
mkdir($workingDir, 0777, true);
chdir($workingDir);
$package = new Package('a', '1.0', '1.0');
$package->setAutoload(array(
'psr-0' => array('Foo' => '../path/../src'),
'classmap' => array('../classmap'),
'files' => array('../test.php'),
));
$this->repository->expects($this->once())
->method('getPackages')
->will($this->returnValue(array()));
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
$this->fs->ensureDirectoryExists($this->workingDir.'/classmap');
file_put_contents($this->workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
file_put_contents($this->workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
file_put_contents($this->workingDir.'/test.php', '<?php class Foo {}');
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_14');
$expectedNamespace = <<<'EOF'
<?php
// autoload_namespaces.php generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir).'/working-dir';
return array(
'Foo' => $baseDir . '/../src',
);
EOF;
$expectedClassmap = <<<'EOF'
<?php
// autoload_classmap.php generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir).'/working-dir';
return array(
'Foo\\Bar' => $baseDir . '/../src/Foo/Bar.php',
'Foo\\Foo' => $baseDir . '/../classmap/classes.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'));
$this->assertContains("require \$baseDir . '/../test.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
}
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
{
$a = __DIR__.'/Fixtures/autoload_'.$name.'.php';