Removing file autoload_files.php was added (#4254)

main
voroks 9 years ago
parent 3d962879a8
commit 4fa1cb2e9c

@ -255,9 +255,12 @@ EOF;
if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
file_put_contents($targetDir.'/include_paths.php', $includePathFile);
}
$includeFilesFilePath = $targetDir.'/autoload_files.php';
if ($includeFilesFile = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
file_put_contents($targetDir.'/autoload_files.php', $includeFilesFile);
}
file_put_contents($includeFilesFilePath, $includeFilesFile);
} else if (file_exists($includeFilesFilePath) === true) {
unlink($includeFilesFilePath);
}
file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix));
file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative));

@ -585,6 +585,71 @@ class AutoloadGeneratorTest extends TestCase
$this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
}
public function testFilesAutoloadGenerationRemoveExtraEntitiesFromAutoloadFiles()
{
$autoloadPackage = new Package('a', '1.0', '1.0');
$autoloadPackage->setAutoload(array('files' => array('root.php')));
$notAutoloadPackage = new Package('a', '1.0', '1.0');
$autoloadPackages = array();
$autoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
$autoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
$autoloadPackages[] = $c = new Package('c/c', '1.0', '1.0');
$a->setAutoload(array('files' => array('test.php')));
$b->setAutoload(array('files' => array('test2.php')));
$c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
$c->setTargetDir('foo/bar');
$notAutoloadPackages = array();
$notAutoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
$notAutoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
$notAutoloadPackages[] = $c = new Package('c/c', '1.0', '1.0');
$this->repository->expects($this->at(0))
->method('getCanonicalPackages')
->will($this->returnValue($autoloadPackages));
$this->repository->expects($this->at(1))
->method('getCanonicalPackages')
->will($this->returnValue($notAutoloadPackages));
$this->repository->expects($this->at(2))
->method('getCanonicalPackages')
->will($this->returnValue($notAutoloadPackages));
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
$this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
file_put_contents($this->vendorDir.'/c/c/foo/bar/test3.php', '<?php function testFilesAutoloadGeneration3() {}');
file_put_contents($this->vendorDir.'/c/c/foo/bar/test4.php', '<?php function testFilesAutoloadGeneration4() {}');
file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
$this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
$this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions_with_removed_extra.php', $this->vendorDir.'/composer/autoload_files.php');
$this->generator->dump($this->config, $this->repository, $notAutoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_removed_extra.php', $this->vendorDir.'/composer/autoload_real.php');
$this->assertFileNotExists($this->vendorDir.'/composer/autoload_files.php');
include $this->vendorDir . '/autoload.php';
$this->assertFalse(function_exists('testFilesAutoloadGeneration1'));
$this->assertFalse(function_exists('testFilesAutoloadGeneration2'));
$this->assertFalse(function_exists('testFilesAutoloadGeneration3'));
$this->assertFalse(function_exists('testFilesAutoloadGeneration4'));
$this->assertFalse(function_exists('testFilesAutoloadGenerationRoot'));
}
public function testFilesAutoloadOrderByDependencies()
{
$package = new Package('a', '1.0', '1.0');

@ -0,0 +1,10 @@
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
$baseDir . '/root.php',
);

@ -0,0 +1,50 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitFilesAutoload
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
}
function composerRequireFilesAutoload($file)
{
require $file;
}
Loading…
Cancel
Save