Merge remote-tracking branch 'hason/autoload'
commit
59c4df5ba3
|
@ -41,18 +41,18 @@ class AutoloadGenerator
|
||||||
{
|
{
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
|
$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
|
||||||
$vendorPath = strtr(realpath($config->get('vendor-dir')), '\\', '/');
|
$basePath = $filesystem->normalizePath(getcwd());
|
||||||
|
$vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir')));
|
||||||
$useGlobalIncludePath = (bool) $config->get('use-include-path');
|
$useGlobalIncludePath = (bool) $config->get('use-include-path');
|
||||||
$targetDir = $vendorPath.'/'.$targetDir;
|
$targetDir = $vendorPath.'/'.$targetDir;
|
||||||
$filesystem->ensureDirectoryExists($targetDir);
|
$filesystem->ensureDirectoryExists($targetDir);
|
||||||
|
|
||||||
$cwd = getcwd();
|
$relVendorPath = $filesystem->findShortestPath($basePath, $vendorPath, true);
|
||||||
$relVendorPath = $filesystem->findShortestPath($cwd, $vendorPath, true);
|
|
||||||
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
|
||||||
$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
|
$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
|
||||||
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
|
$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);
|
||||||
|
|
||||||
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $cwd, true);
|
$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
|
||||||
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
|
$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);
|
||||||
|
|
||||||
$namespacesFile = <<<EOF
|
$namespacesFile = <<<EOF
|
||||||
|
@ -73,7 +73,7 @@ EOF;
|
||||||
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
||||||
$exportedPaths = array();
|
$exportedPaths = array();
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
$exportedPaths[] = $this->getPathCode($filesystem, $relVendorPath, $vendorPath, $path);
|
$exportedPaths[] = $this->getPathCode($filesystem, $basePath, $relVendorPath, $vendorPath, $path);
|
||||||
}
|
}
|
||||||
$exportedPrefix = var_export($namespace, true);
|
$exportedPrefix = var_export($namespace, true);
|
||||||
$namespacesFile .= " $exportedPrefix => ";
|
$namespacesFile .= " $exportedPrefix => ";
|
||||||
|
@ -101,11 +101,11 @@ EOF;
|
||||||
$targetDirLoader = null;
|
$targetDirLoader = null;
|
||||||
$mainAutoload = $mainPackage->getAutoload();
|
$mainAutoload = $mainPackage->getAutoload();
|
||||||
if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) {
|
if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) {
|
||||||
$levels = count(explode('/', trim(strtr($mainPackage->getTargetDir(), '\\', '/'), '/')));
|
$levels = count(explode('/', $filesystem->normalizePath($mainPackage->getTargetDir())));
|
||||||
$prefixes = implode(', ', array_map(function ($prefix) {
|
$prefixes = implode(', ', array_map(function ($prefix) {
|
||||||
return var_export($prefix, true);
|
return var_export($prefix, true);
|
||||||
}, array_keys($mainAutoload['psr-0'])));
|
}, array_keys($mainAutoload['psr-0'])));
|
||||||
$baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, $cwd, true);
|
$baseDirFromTargetDirCode = $filesystem->findShortestPathCode($targetDir, $basePath, true);
|
||||||
|
|
||||||
$targetDirLoader = <<<EOF
|
$targetDirLoader = <<<EOF
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ EOF;
|
||||||
if ($scanPsr0Packages) {
|
if ($scanPsr0Packages) {
|
||||||
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
foreach ($autoloads['psr-0'] as $namespace => $paths) {
|
||||||
foreach ($paths as $dir) {
|
foreach ($paths as $dir) {
|
||||||
$dir = $this->getPath($filesystem, $relVendorPath, $vendorPath, $dir);
|
$dir = $this->getPath($filesystem, $basePath, $relVendorPath, $vendorPath, $dir);
|
||||||
$whitelist = sprintf(
|
$whitelist = sprintf(
|
||||||
'{%s/%s.+(?<!(?<!/)Test\.php)$}',
|
'{%s/%s.+(?<!(?<!/)Test\.php)$}',
|
||||||
preg_quote(rtrim($dir, '/')),
|
preg_quote(rtrim($dir, '/')),
|
||||||
|
@ -146,9 +146,9 @@ EOF;
|
||||||
}
|
}
|
||||||
foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) {
|
foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) {
|
||||||
if ('' === $namespace || 0 === strpos($class, $namespace)) {
|
if ('' === $namespace || 0 === strpos($class, $namespace)) {
|
||||||
$path = '/'.$filesystem->findShortestPath($cwd, $path, true);
|
|
||||||
if (!isset($classMap[$class])) {
|
if (!isset($classMap[$class])) {
|
||||||
$classMap[$class] = '$baseDir . '.var_export($path, true).",\n";
|
$path = $this->getPathCode($filesystem, $basePath, $relVendorPath, $vendorPath, $path);
|
||||||
|
$classMap[$class] = $path.",\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,12 +159,8 @@ EOF;
|
||||||
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
$autoloads['classmap'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['classmap']));
|
||||||
foreach ($autoloads['classmap'] as $dir) {
|
foreach ($autoloads['classmap'] as $dir) {
|
||||||
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
|
foreach (ClassMapGenerator::createMap($dir) as $class => $path) {
|
||||||
$path = $filesystem->findShortestPath($cwd, $path, true);
|
$path = $this->getPathCode($filesystem, $basePath, $relVendorPath, $vendorPath, $path);
|
||||||
if ($filesystem->isAbsolutePath($path)) {
|
$classMap[$class] = $path.",\n";
|
||||||
$classMap[$class] = var_export($path, true).",\n";
|
|
||||||
} else {
|
|
||||||
$classMap[$class] = '$baseDir . '.var_export('/'.$path, true).",\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +173,7 @@ EOF;
|
||||||
$filesCode = "";
|
$filesCode = "";
|
||||||
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
|
$autoloads['files'] = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($autoloads['files']));
|
||||||
foreach ($autoloads['files'] as $functionFile) {
|
foreach ($autoloads['files'] as $functionFile) {
|
||||||
$filesCode .= ' require '.$this->getPathCode($filesystem, $relVendorPath, $vendorPath, $functionFile).";\n";
|
$filesCode .= ' require '.$this->getPathCode($filesystem, $basePath, $relVendorPath, $vendorPath, $functionFile).";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$suffix) {
|
if (!$suffix) {
|
||||||
|
@ -186,7 +182,7 @@ EOF;
|
||||||
|
|
||||||
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile);
|
||||||
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile);
|
||||||
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $relVendorPath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
|
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $relVendorPath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
|
||||||
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
|
||||||
}
|
}
|
||||||
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
|
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
|
||||||
|
@ -257,7 +253,7 @@ EOF;
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)
|
protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $basePath, $relVendorPath, $vendorPath, $vendorPathCode, $appBaseDirCode)
|
||||||
{
|
{
|
||||||
$includePaths = array();
|
$includePaths = array();
|
||||||
|
|
||||||
|
@ -291,15 +287,15 @@ return array(
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
foreach ($includePaths as $path) {
|
foreach ($includePaths as $path) {
|
||||||
$includePathsFile .= " " . $this->getPathCode($filesystem, $relVendorPath, $vendorPath, $path) . ",\n";
|
$includePathsFile .= " " . $this->getPathCode($filesystem, $basePath, $relVendorPath, $vendorPath, $path) . ",\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $includePathsFile . ");\n";
|
return $includePathsFile . ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPathCode(Filesystem $filesystem, $relVendorPath, $vendorPath, $path)
|
protected function getPathCode(Filesystem $filesystem, $basePath, $relVendorPath, $vendorPath, $path)
|
||||||
{
|
{
|
||||||
$path = strtr($path, '\\', '/');
|
$path = $filesystem->normalizePath($path);
|
||||||
$baseDir = '';
|
$baseDir = '';
|
||||||
if (!$filesystem->isAbsolutePath($path)) {
|
if (!$filesystem->isAbsolutePath($path)) {
|
||||||
if (strpos($path, $relVendorPath) === 0) {
|
if (strpos($path, $relVendorPath) === 0) {
|
||||||
|
@ -313,6 +309,9 @@ EOF;
|
||||||
} elseif (strpos($path, $vendorPath) === 0) {
|
} elseif (strpos($path, $vendorPath) === 0) {
|
||||||
$path = substr($path, strlen($vendorPath));
|
$path = substr($path, strlen($vendorPath));
|
||||||
$baseDir = '$vendorDir . ';
|
$baseDir = '$vendorDir . ';
|
||||||
|
} elseif (strpos($path, $basePath) === 0) {
|
||||||
|
$path = substr($path, strlen($basePath));
|
||||||
|
$baseDir = '$baseDir . ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('/\.phar$/', $path)){
|
if (preg_match('/\.phar$/', $path)){
|
||||||
|
@ -322,16 +321,16 @@ EOF;
|
||||||
return $baseDir.var_export($path, true);
|
return $baseDir.var_export($path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPath(Filesystem $filesystem, $relVendorPath, $vendorPath, $path)
|
protected function getPath(Filesystem $filesystem, $basePath, $relVendorPath, $vendorPath, $path)
|
||||||
{
|
{
|
||||||
$path = strtr($path, '\\', '/');
|
$path = $filesystem->normalizePath($path);
|
||||||
if (!$filesystem->isAbsolutePath($path)) {
|
if (!$filesystem->isAbsolutePath($path)) {
|
||||||
if (strpos($path, $relVendorPath) === 0) {
|
if (strpos($path, $relVendorPath) === 0) {
|
||||||
// path starts with vendor dir
|
// path starts with vendor dir
|
||||||
return $vendorPath . substr($path, strlen($relVendorPath));
|
return $vendorPath . substr($path, strlen($relVendorPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
return strtr(getcwd(), '\\', '/').'/'.$path;
|
return $basePath.'/'.$path;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
|
|
|
@ -202,8 +202,8 @@ class Filesystem
|
||||||
throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to));
|
throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to));
|
||||||
}
|
}
|
||||||
|
|
||||||
$from = lcfirst(rtrim(strtr($from, '\\', '/'), '/'));
|
$from = lcfirst($this->normalizePath($from));
|
||||||
$to = lcfirst(rtrim(strtr($to, '\\', '/'), '/'));
|
$to = lcfirst($this->normalizePath($to));
|
||||||
|
|
||||||
if ($directories) {
|
if ($directories) {
|
||||||
$from .= '/dummy_file';
|
$from .= '/dummy_file';
|
||||||
|
@ -243,8 +243,8 @@ class Filesystem
|
||||||
throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to));
|
throw new \InvalidArgumentException(sprintf('$from (%s) and $to (%s) must be absolute paths.', $from, $to));
|
||||||
}
|
}
|
||||||
|
|
||||||
$from = lcfirst(strtr($from, '\\', '/'));
|
$from = lcfirst($this->normalizePath($from));
|
||||||
$to = lcfirst(strtr($to, '\\', '/'));
|
$to = lcfirst($this->normalizePath($to));
|
||||||
|
|
||||||
if ($from === $to) {
|
if ($from === $to) {
|
||||||
return $directories ? '__DIR__' : '__FILE__';
|
return $directories ? '__DIR__' : '__FILE__';
|
||||||
|
@ -300,6 +300,35 @@ class Filesystem
|
||||||
return filesize($path);
|
return filesize($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a path. This replaces backslashes with slashes, removes ending
|
||||||
|
* slash and collapses redundant separators and up-level references.
|
||||||
|
*
|
||||||
|
* @param string $path Path to the file or directory
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function normalizePath($path)
|
||||||
|
{
|
||||||
|
$parts = array();
|
||||||
|
$path = strtr($path, '\\', '/');
|
||||||
|
$prefix = '';
|
||||||
|
|
||||||
|
if (preg_match('|^(([a-z]:)?/)|i', $path, $match)) {
|
||||||
|
$prefix = $match[1];
|
||||||
|
$path = substr($path, strlen($prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (explode('/', $path) as $chunk) {
|
||||||
|
if ('..' === $chunk) {
|
||||||
|
array_pop($parts);
|
||||||
|
} elseif ('.' !== $chunk && '' !== $chunk) {
|
||||||
|
$parts[] = $chunk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $prefix.implode('/', $parts);
|
||||||
|
}
|
||||||
|
|
||||||
protected function directorySize($directory)
|
protected function directorySize($directory)
|
||||||
{
|
{
|
||||||
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
|
$it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
|
|
|
@ -261,12 +261,12 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
|
||||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->normalizePaths(array(
|
array(
|
||||||
'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
|
'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
|
||||||
'ClassMapBaz' => $this->vendorDir.'/b/b/lib/c.php',
|
'ClassMapBaz' => $this->vendorDir.'/b/b/lib/c.php',
|
||||||
'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
|
'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
|
||||||
)),
|
),
|
||||||
$this->normalizePaths(include $this->vendorDir.'/composer/autoload_classmap.php')
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
||||||
);
|
);
|
||||||
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
|
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
|
||||||
}
|
}
|
||||||
|
@ -297,12 +297,12 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
|
||||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->normalizePaths(array(
|
array(
|
||||||
'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
|
'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
|
||||||
'ClassMapBaz' => $this->vendorDir.'/b/b/src/c.php',
|
'ClassMapBaz' => $this->vendorDir.'/b/b/src/c.php',
|
||||||
'ClassMapFoo' => $this->vendorDir.'/a/a/target/src/a.php',
|
'ClassMapFoo' => $this->vendorDir.'/a/a/target/src/a.php',
|
||||||
)),
|
),
|
||||||
$this->normalizePaths(include $this->vendorDir.'/composer/autoload_classmap.php')
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,12 +333,12 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
|
||||||
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->normalizePaths(array(
|
array(
|
||||||
'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
|
'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
|
||||||
'ClassMapBaz' => $this->vendorDir.'/c/c/foo/test.php',
|
'ClassMapBaz' => $this->vendorDir.'/c/c/foo/test.php',
|
||||||
'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
|
'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
|
||||||
)),
|
),
|
||||||
$this->normalizePaths(include $this->vendorDir.'/composer/autoload_classmap.php')
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
||||||
);
|
);
|
||||||
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
|
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
|
||||||
}
|
}
|
||||||
|
@ -469,7 +469,6 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
file_put_contents($this->vendorDir.'/a/a/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
|
file_put_contents($this->vendorDir.'/a/a/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
|
||||||
file_put_contents($this->vendorDir.'/a/a/classmap/classes.php', '<?php namespace Foo; class Bar {}');
|
file_put_contents($this->vendorDir.'/a/a/classmap/classes.php', '<?php namespace Foo; class Bar {}');
|
||||||
|
|
||||||
$workDir = strtr($this->workingDir, '\\', '/');
|
|
||||||
$expectedNamespace = <<<EOF
|
$expectedNamespace = <<<EOF
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -479,9 +478,9 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
\$baseDir = dirname(\$vendorDir);
|
\$baseDir = dirname(\$vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'B\\\\Sub\\\\Name' => \$vendorDir . '/b/b/src/',
|
'B\\\\Sub\\\\Name' => \$vendorDir . '/b/b/src',
|
||||||
'A\\\\B' => array('$workDir/lib', \$vendorDir . '/a/a/lib/'),
|
'A\\\\B' => array(\$baseDir . '/lib', \$vendorDir . '/a/a/lib'),
|
||||||
'A' => \$vendorDir . '/a/a/src/',
|
'A' => \$vendorDir . '/a/a/src',
|
||||||
);
|
);
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
@ -660,27 +659,101 @@ EOF;
|
||||||
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php');
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testVendorDirExcludedFromWorkingDir()
|
||||||
|
{
|
||||||
|
$workingDir = $this->vendorDir.'/working-dir';
|
||||||
|
$vendorDir = $workingDir.'/../vendor';
|
||||||
|
|
||||||
|
$this->fs->ensureDirectoryExists($workingDir);
|
||||||
|
chdir($workingDir);
|
||||||
|
|
||||||
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
$package->setAutoload(array(
|
||||||
|
'psr-0' => array('Foo' => 'src'),
|
||||||
|
'classmap' => array('classmap'),
|
||||||
|
'files' => array('test.php'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$vendorPackage = new Package('b/b', '1.0', '1.0');
|
||||||
|
$vendorPackage->setAutoload(array(
|
||||||
|
'psr-0' => array('Bar' => 'lib'),
|
||||||
|
'classmap' => array('classmaps'),
|
||||||
|
'files' => array('bootstrap.php'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->repository->expects($this->once())
|
||||||
|
->method('getPackages')
|
||||||
|
->will($this->returnValue(array($vendorPackage)));
|
||||||
|
|
||||||
|
$im = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$im->expects($this->any())
|
||||||
|
->method('getInstallPath')
|
||||||
|
->will($this->returnCallback(function ($package) use ($vendorDir) {
|
||||||
|
$targetDir = $package->getTargetDir();
|
||||||
|
return $vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
|
||||||
|
}));
|
||||||
|
|
||||||
|
$this->fs->ensureDirectoryExists($workingDir.'/src/Foo');
|
||||||
|
$this->fs->ensureDirectoryExists($workingDir.'/classmap');
|
||||||
|
$this->fs->ensureDirectoryExists($vendorDir.'/composer');
|
||||||
|
$this->fs->ensureDirectoryExists($vendorDir.'/b/b/lib/Bar');
|
||||||
|
$this->fs->ensureDirectoryExists($vendorDir.'/b/b/classmaps');
|
||||||
|
file_put_contents($workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
|
||||||
|
file_put_contents($workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
|
||||||
|
file_put_contents($workingDir.'/test.php', '<?php class Foo {}');
|
||||||
|
file_put_contents($vendorDir.'/b/b/lib/Bar/Foo.php', '<?php namespace Bar; class Foo {}');
|
||||||
|
file_put_contents($vendorDir.'/b/b/classmaps/classes.php', '<?php namespace Bar; class Bar {}');
|
||||||
|
file_put_contents($vendorDir.'/b/b/bootstrap.php', '<?php class Bar {}');
|
||||||
|
|
||||||
|
$oldVendorDir = $this->vendorDir;
|
||||||
|
$this->vendorDir = $vendorDir;
|
||||||
|
$this->generator->dump($this->config, $this->repository, $package, $im, 'composer', true, '_13');
|
||||||
|
$this->vendorDir = $oldVendorDir;
|
||||||
|
|
||||||
|
$expectedNamespace = <<<'EOF'
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_namespaces.php generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(dirname(__FILE__));
|
||||||
|
$baseDir = dirname($vendorDir).'/working-dir';
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'Foo' => $baseDir . '/src',
|
||||||
|
'Bar' => $vendorDir . '/b/b/lib',
|
||||||
|
);
|
||||||
|
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
$expectedClassmap = <<<'EOF'
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// autoload_classmap.php generated by Composer
|
||||||
|
|
||||||
|
$vendorDir = dirname(dirname(__FILE__));
|
||||||
|
$baseDir = dirname($vendorDir).'/working-dir';
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'Bar\\Bar' => $vendorDir . '/b/b/classmaps/classes.php',
|
||||||
|
'Bar\\Foo' => $vendorDir . '/b/b/lib/Bar/Foo.php',
|
||||||
|
'Foo\\Bar' => $baseDir . '/src/Foo/Bar.php',
|
||||||
|
'Foo\\Foo' => $baseDir . '/classmap/classes.php',
|
||||||
|
);
|
||||||
|
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
$this->assertEquals($expectedNamespace, file_get_contents($vendorDir.'/composer/autoload_namespaces.php'));
|
||||||
|
$this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php'));
|
||||||
|
$this->assertContains("require \$vendorDir . '/b/b/bootstrap.php';", file_get_contents($vendorDir.'/composer/autoload_real.php'));
|
||||||
|
$this->assertContains("require \$baseDir . '/test.php';", file_get_contents($vendorDir.'/composer/autoload_real.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';
|
||||||
$b = $dir.'/autoload_'.$type.'.php';
|
$b = $dir.'/autoload_'.$type.'.php';
|
||||||
$this->assertEquals(
|
$this->assertFileEquals($a, $b);
|
||||||
str_replace('%vendorDir%', basename($this->vendorDir), file_get_contents($a)),
|
|
||||||
file_get_contents($b),
|
|
||||||
$a .' does not equal '. $b
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function normalizePaths($paths)
|
|
||||||
{
|
|
||||||
if (!is_array($paths)) {
|
|
||||||
return strtr($paths, '\\', '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($paths as $key => $path) {
|
|
||||||
$paths[$key] = strtr($path, '\\', '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $paths;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = $vendorDir;
|
$baseDir = $vendorDir;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'ClassMapFoo' => $baseDir . '/composersrc/foo.php',
|
'ClassMapFoo' => $vendorDir . '/composersrc/foo.php',
|
||||||
'Main\\Foo' => $baseDir . '/src/Main/Foo.php',
|
'Main\\Foo' => $vendorDir . '/src/Main/Foo.php',
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'ClassMapBar' => $baseDir . '/%vendorDir%/b/b/src/b.php',
|
'ClassMapBar' => $vendorDir . '/b/b/src/b.php',
|
||||||
'ClassMapBaz' => $baseDir . '/%vendorDir%/b/b/lib/c.php',
|
'ClassMapBaz' => $vendorDir . '/b/b/lib/c.php',
|
||||||
'ClassMapFoo' => $baseDir . '/%vendorDir%/a/a/src/a.php',
|
'ClassMapFoo' => $vendorDir . '/a/a/src/a.php',
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'ClassMapBar' => $baseDir . '/%vendorDir%/b/b/test.php',
|
'ClassMapBar' => $vendorDir . '/b/b/test.php',
|
||||||
'ClassMapBaz' => $baseDir . '/%vendorDir%/c/c/foo/test.php',
|
'ClassMapBaz' => $vendorDir . '/c/c/foo/test.php',
|
||||||
'ClassMapFoo' => $baseDir . '/%vendorDir%/a/a/src/a.php',
|
'ClassMapFoo' => $vendorDir . '/a/a/src/a.php',
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'Main' => $baseDir . '/src/',
|
'Main' => $baseDir . '/src',
|
||||||
'Lala' => array($baseDir . '/src/', $baseDir . '/lib/'),
|
'Lala' => array($baseDir . '/src', $baseDir . '/lib'),
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = dirname(dirname($vendorDir));
|
$baseDir = dirname(dirname($vendorDir));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'Main' => $baseDir . '/src/',
|
'Main' => $baseDir . '/src',
|
||||||
'Lala' => $baseDir . '/src/',
|
'Lala' => $baseDir . '/src',
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,6 +6,6 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = $vendorDir;
|
$baseDir = $vendorDir;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'Main' => $baseDir . '/src/',
|
'Main' => $baseDir . '/src',
|
||||||
'Lala' => $baseDir . '/src/',
|
'Lala' => $baseDir . '/src',
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
|
||||||
$baseDir = dirname($vendorDir);
|
$baseDir = dirname($vendorDir);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'B\\Sub\\Name' => $vendorDir . '/b/b/src/',
|
'B\\Sub\\Name' => $vendorDir . '/b/b/src',
|
||||||
'A\\B' => $vendorDir . '/a/a/lib/',
|
'A\\B' => $vendorDir . '/a/a/lib',
|
||||||
'A' => $vendorDir . '/a/a/src/',
|
'A' => $vendorDir . '/a/a/src',
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,6 +38,7 @@ class FilesystemTest extends TestCase
|
||||||
array('c:/bin/run', 'd:/vendor/acme/bin/run', false, "'d:/vendor/acme/bin/run'"),
|
array('c:/bin/run', 'd:/vendor/acme/bin/run', false, "'d:/vendor/acme/bin/run'"),
|
||||||
array('c:\\bin\\run', 'd:/vendor/acme/bin/run', false, "'d:/vendor/acme/bin/run'"),
|
array('c:\\bin\\run', 'd:/vendor/acme/bin/run', false, "'d:/vendor/acme/bin/run'"),
|
||||||
array('/foo/bar', '/foo/bar', true, "__DIR__"),
|
array('/foo/bar', '/foo/bar', true, "__DIR__"),
|
||||||
|
array('/foo/bar/', '/foo/bar', true, "__DIR__"),
|
||||||
array('/foo/bar', '/foo/baz', true, "dirname(__DIR__).'/baz'"),
|
array('/foo/bar', '/foo/baz', true, "dirname(__DIR__).'/baz'"),
|
||||||
array('/foo/bin/run', '/foo/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"),
|
array('/foo/bin/run', '/foo/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"),
|
||||||
array('/foo/bin/run', '/bar/bin/run', true, "'/bar/bin/run'"),
|
array('/foo/bin/run', '/bar/bin/run', true, "'/bar/bin/run'"),
|
||||||
|
@ -52,6 +53,11 @@ class FilesystemTest extends TestCase
|
||||||
array('/tmp/test', '/tmp', true, "dirname(__DIR__)"),
|
array('/tmp/test', '/tmp', true, "dirname(__DIR__)"),
|
||||||
array('/tmp', '/tmp/test', true, "__DIR__ . '/test'"),
|
array('/tmp', '/tmp/test', true, "__DIR__ . '/test'"),
|
||||||
array('C:/Temp', 'c:\Temp\test', true, "__DIR__ . '/test'"),
|
array('C:/Temp', 'c:\Temp\test', true, "__DIR__ . '/test'"),
|
||||||
|
array('/tmp/test/./', '/tmp/test/', true, '__DIR__'),
|
||||||
|
array('/tmp/test/../vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"),
|
||||||
|
array('/tmp/test/.././vendor', '/tmp/test', true, "dirname(__DIR__).'/test'"),
|
||||||
|
array('C:/Temp', 'c:\Temp\..\..\test', true, "dirname(__DIR__).'/test'"),
|
||||||
|
array('C:/Temp/../..', 'd:\Temp\..\..\test', true, "'d:/test'"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +97,12 @@ class FilesystemTest extends TestCase
|
||||||
array('/tmp', '/tmp/test', "test"),
|
array('/tmp', '/tmp/test', "test"),
|
||||||
array('C:/Temp', 'C:\Temp\test', "test"),
|
array('C:/Temp', 'C:\Temp\test', "test"),
|
||||||
array('C:/Temp', 'c:\Temp\test', "test"),
|
array('C:/Temp', 'c:\Temp\test', "test"),
|
||||||
|
array('/tmp/test/./', '/tmp/test', './', true),
|
||||||
|
array('/tmp/test/../vendor', '/tmp/test', '../test', true),
|
||||||
|
array('/tmp/test/.././vendor', '/tmp/test', '../test', true),
|
||||||
|
array('C:/Temp', 'c:\Temp\..\..\test', "../test", true),
|
||||||
|
array('C:/Temp/../..', 'c:\Temp\..\..\test', "./test", true),
|
||||||
|
array('/tmp', '/tmp/../../test', '/test', true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue