2011-12-03 22:20:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2012-03-08 13:17:22 +00:00
|
|
|
namespace Composer\Test\Autoload;
|
2011-12-03 22:20:06 +00:00
|
|
|
|
|
|
|
use Composer\Autoload\AutoloadGenerator;
|
2012-09-01 11:24:17 +00:00
|
|
|
use Composer\Package\Link;
|
2012-02-09 17:45:28 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2012-05-14 12:01:37 +00:00
|
|
|
use Composer\Package\AliasPackage;
|
2012-08-23 13:52:40 +00:00
|
|
|
use Composer\Package\Package;
|
2013-09-25 08:14:42 +00:00
|
|
|
use Composer\TestCase;
|
2013-01-06 19:34:52 +00:00
|
|
|
use Composer\Script\ScriptEvents;
|
2013-12-22 20:56:58 +00:00
|
|
|
use Composer\Repository\InstalledRepositoryInterface;
|
|
|
|
use Composer\Installer\InstallationManager;
|
|
|
|
use Composer\Config;
|
|
|
|
use Composer\EventDispatcher\EventDispatcher;
|
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
class AutoloadGeneratorTest extends TestCase
|
2011-12-03 22:20:06 +00:00
|
|
|
{
|
2013-12-22 20:56:58 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-12-03 22:20:06 +00:00
|
|
|
public $vendorDir;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Config|MockObject
|
|
|
|
*/
|
2012-06-24 19:58:51 +00:00
|
|
|
private $config;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-12-03 22:20:06 +00:00
|
|
|
private $workingDir;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var InstallationManager|MockObject
|
|
|
|
*/
|
2011-12-03 22:20:06 +00:00
|
|
|
private $im;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var InstalledRepositoryInterface|MockObject
|
|
|
|
*/
|
2011-12-03 22:20:06 +00:00
|
|
|
private $repository;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AutoloadGenerator
|
|
|
|
*/
|
2011-12-03 22:20:06 +00:00
|
|
|
private $generator;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Filesystem
|
|
|
|
*/
|
2012-02-24 09:40:47 +00:00
|
|
|
private $fs;
|
2013-12-22 20:56:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EventDispatcher|MockObject
|
|
|
|
*/
|
2013-01-06 19:34:52 +00:00
|
|
|
private $eventDispatcher;
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2015-01-04 00:35:25 +00:00
|
|
|
/**
|
2015-01-04 01:01:18 +00:00
|
|
|
* Map of setting name => return value configuration for the stub Config
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* Note: must be public for compatibility with PHP 5.3 runtimes where
|
|
|
|
* closures cannot access private members of the classes they are created
|
|
|
|
* in.
|
2015-01-04 00:35:25 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2015-01-04 01:01:18 +00:00
|
|
|
public $configValueMap;
|
2015-01-04 00:35:25 +00:00
|
|
|
|
2011-12-03 22:20:06 +00:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2012-02-24 09:40:47 +00:00
|
|
|
$this->fs = new Filesystem;
|
2011-12-03 22:20:06 +00:00
|
|
|
$that = $this;
|
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
$this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir);
|
2013-02-20 15:50:26 +00:00
|
|
|
$this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload';
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->ensureDirectoryExistsAndClear($this->vendorDir);
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2012-06-24 19:58:51 +00:00
|
|
|
$this->config = $this->getMock('Composer\Config');
|
2013-01-14 08:32:26 +00:00
|
|
|
|
2015-01-04 00:35:25 +00:00
|
|
|
$this->configValueMap = array(
|
|
|
|
'vendor-dir' => function () use ($that) {
|
2012-06-24 19:58:51 +00:00
|
|
|
return $that->vendorDir;
|
2015-01-04 00:35:25 +00:00
|
|
|
},
|
|
|
|
);
|
2012-06-24 19:58:51 +00:00
|
|
|
|
2015-01-04 00:35:25 +00:00
|
|
|
$this->config->expects($this->atLeastOnce())
|
2013-01-14 08:32:26 +00:00
|
|
|
->method('get')
|
2015-01-04 00:35:25 +00:00
|
|
|
->will($this->returnCallback(function ($arg) use ($that) {
|
|
|
|
$ret = null;
|
|
|
|
if (isset($that->configValueMap[$arg])) {
|
|
|
|
$ret = $that->configValueMap[$arg];
|
|
|
|
if (is_callable($ret)) {
|
|
|
|
$ret = $ret();
|
|
|
|
}
|
|
|
|
}
|
2015-02-24 14:22:54 +00:00
|
|
|
|
2015-01-04 00:35:25 +00:00
|
|
|
return $ret;
|
2013-01-14 08:32:26 +00:00
|
|
|
}));
|
|
|
|
|
2013-02-20 15:50:26 +00:00
|
|
|
$this->origDir = getcwd();
|
2011-12-03 22:20:06 +00:00
|
|
|
chdir($this->workingDir);
|
|
|
|
|
|
|
|
$this->im = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->im->expects($this->any())
|
|
|
|
->method('getInstallPath')
|
|
|
|
->will($this->returnCallback(function ($package) use ($that) {
|
2013-01-31 22:39:57 +00:00
|
|
|
$targetDir = $package->getTargetDir();
|
2013-06-13 11:28:24 +00:00
|
|
|
|
2013-01-31 22:39:57 +00:00
|
|
|
return $that->vendorDir.'/'.$package->getName() . ($targetDir ? '/'.$targetDir : '');
|
2011-12-03 22:20:06 +00:00
|
|
|
}));
|
2013-04-28 20:32:46 +00:00
|
|
|
$this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2013-08-14 15:42:11 +00:00
|
|
|
$this->eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
|
2013-01-06 19:34:52 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->generator = new AutoloadGenerator($this->eventDispatcher);
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
2013-02-20 15:50:26 +00:00
|
|
|
chdir($this->origDir);
|
2012-06-19 21:15:42 +00:00
|
|
|
|
|
|
|
if (is_dir($this->workingDir)) {
|
|
|
|
$this->fs->removeDirectory($this->workingDir);
|
2012-02-24 09:40:47 +00:00
|
|
|
}
|
2012-06-19 21:15:42 +00:00
|
|
|
if (is_dir($this->vendorDir)) {
|
|
|
|
$this->fs->removeDirectory($this->vendorDir);
|
2012-03-21 12:58:35 +00:00
|
|
|
}
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMainPackageAutoloading()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-03-21 12:58:35 +00:00
|
|
|
$package->setAutoload(array(
|
2013-11-26 01:53:44 +00:00
|
|
|
'psr-0' => array(
|
|
|
|
'Main' => 'src/',
|
|
|
|
'Lala' => array('src/', 'lib/'),
|
|
|
|
),
|
|
|
|
'psr-4' => array(
|
|
|
|
'Acme\Fruit\\' => 'src-fruit/',
|
|
|
|
'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
|
|
|
|
),
|
2012-04-22 20:11:03 +00:00
|
|
|
'classmap' => array('composersrc/'),
|
2012-03-21 12:58:35 +00:00
|
|
|
));
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2011-12-03 22:20:06 +00:00
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/composer');
|
2015-06-12 15:52:55 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Lala/Test');
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/lib');
|
2014-02-03 15:53:56 +00:00
|
|
|
file_put_contents($this->workingDir.'/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
|
2015-06-12 15:52:55 +00:00
|
|
|
file_put_contents($this->workingDir.'/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\Test; class ClassMapMainTest {}');
|
2012-03-21 12:58:35 +00:00
|
|
|
|
2013-11-26 01:53:44 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src-fruit');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src-cake');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/lib-cake');
|
2014-02-03 15:53:56 +00:00
|
|
|
file_put_contents($this->workingDir.'/src-cake/ClassMapBar.php', '<?php namespace Acme\Cake; class ClassMapBar {}');
|
2013-11-26 01:53:44 +00:00
|
|
|
|
2013-02-19 14:23:43 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
|
|
|
|
file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
|
2012-03-21 12:58:35 +00:00
|
|
|
|
2014-02-03 15:53:56 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
|
2013-11-26 01:53:44 +00:00
|
|
|
|
|
|
|
// Assert that autoload_namespaces.php was correctly generated.
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
|
2013-11-26 01:53:44 +00:00
|
|
|
|
|
|
|
// Assert that autoload_psr4.php was correctly generated.
|
|
|
|
$this->assertAutoloadFiles('psr4', $this->vendorDir.'/composer', 'psr4');
|
|
|
|
|
|
|
|
// Assert that autoload_classmap.php was correctly generated.
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
2014-03-01 19:39:06 +00:00
|
|
|
|
2014-02-27 09:39:33 +00:00
|
|
|
public function testMainPackageDevAutoloading()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array(
|
|
|
|
'Main' => 'src/',
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$package->setDevAutoload(array(
|
|
|
|
'files' => array('devfiles/foo.php'),
|
2014-03-01 19:39:06 +00:00
|
|
|
'psr-0' => array(
|
|
|
|
'Main' => 'tests/'
|
|
|
|
),
|
2014-02-27 09:39:33 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
|
|
|
->method('getCanonicalPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Main');
|
|
|
|
file_put_contents($this->workingDir.'/src/Main/ClassMain.php', '<?php namespace Main; class ClassMain {}');
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/devfiles');
|
|
|
|
file_put_contents($this->workingDir.'/devfiles/foo.php', '<?php function foo() { echo "foo"; }');
|
|
|
|
|
|
|
|
// generate autoload files with the dev mode set to true
|
|
|
|
$this->generator->setDevMode(true);
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
|
2014-03-01 19:39:06 +00:00
|
|
|
|
2014-02-27 09:39:33 +00:00
|
|
|
// check standard autoload
|
2014-03-01 19:39:06 +00:00
|
|
|
$this->assertAutoloadFiles('main5', $this->vendorDir.'/composer');
|
2014-02-27 09:39:33 +00:00
|
|
|
$this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap');
|
2014-03-01 19:39:06 +00:00
|
|
|
|
2014-02-27 09:39:33 +00:00
|
|
|
// make sure dev autoload is correctly dumped
|
|
|
|
$this->assertAutoloadFiles('files2', $this->vendorDir.'/composer', 'files');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMainPackageDevAutoloadingDisabledByDefault()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array(
|
|
|
|
'Main' => 'src/',
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$package->setDevAutoload(array(
|
|
|
|
'files' => array('devfiles/foo.php'),
|
|
|
|
));
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2014-02-27 09:39:33 +00:00
|
|
|
$this->repository->expects($this->once())
|
|
|
|
->method('getCanonicalPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Main');
|
|
|
|
file_put_contents($this->workingDir.'/src/Main/ClassMain.php', '<?php namespace Main; class ClassMain {}');
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/devfiles');
|
|
|
|
file_put_contents($this->workingDir.'/devfiles/foo.php', '<?php function foo() { echo "foo"; }');
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
|
|
|
|
|
|
|
|
// check standard autoload
|
|
|
|
$this->assertAutoloadFiles('main4', $this->vendorDir.'/composer');
|
|
|
|
$this->assertAutoloadFiles('classmap7', $this->vendorDir.'/composer', 'classmap');
|
|
|
|
|
|
|
|
// make sure dev autoload is disabled when dev mode is set to false
|
|
|
|
$this->assertFalse(is_file($this->vendorDir.'/composer/autoload_files.php'));
|
|
|
|
}
|
2014-03-01 19:39:06 +00:00
|
|
|
|
2012-01-31 14:04:49 +00:00
|
|
|
public function testVendorDirSameAsWorkingDir()
|
|
|
|
{
|
2012-02-02 15:38:48 +00:00
|
|
|
$this->vendorDir = $this->workingDir;
|
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-03-21 12:58:35 +00:00
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
|
2013-11-26 01:53:44 +00:00
|
|
|
'psr-4' => array(
|
|
|
|
'Acme\Fruit\\' => 'src-fruit/',
|
|
|
|
'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
|
|
|
|
),
|
2012-04-22 20:11:03 +00:00
|
|
|
'classmap' => array('composersrc/'),
|
2012-03-21 12:58:35 +00:00
|
|
|
));
|
2012-02-02 15:38:48 +00:00
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-02-02 15:38:48 +00:00
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/src/Main');
|
|
|
|
file_put_contents($this->vendorDir.'/src/Main/Foo.php', '<?php namespace Main; class Foo {}');
|
2012-02-24 11:28:41 +00:00
|
|
|
|
2013-02-19 14:23:43 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composersrc');
|
|
|
|
file_put_contents($this->vendorDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
|
2012-03-21 12:58:35 +00:00
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_2');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('main3', $this->vendorDir.'/composer');
|
2013-11-26 01:53:44 +00:00
|
|
|
$this->assertAutoloadFiles('psr4_3', $this->vendorDir.'/composer', 'psr4');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('classmap3', $this->vendorDir.'/composer', 'classmap');
|
2012-01-31 14:04:49 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 22:20:06 +00:00
|
|
|
public function testMainPackageAutoloadingAlternativeVendorDir()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-03-21 12:58:35 +00:00
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
|
2013-11-26 01:53:44 +00:00
|
|
|
'psr-4' => array(
|
|
|
|
'Acme\Fruit\\' => 'src-fruit/',
|
|
|
|
'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
|
|
|
|
),
|
2012-04-22 20:11:03 +00:00
|
|
|
'classmap' => array('composersrc/'),
|
2012-03-21 12:58:35 +00:00
|
|
|
));
|
2011-12-03 22:20:06 +00:00
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2011-12-03 22:20:06 +00:00
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$this->vendorDir .= '/subdir';
|
2012-06-19 21:15:42 +00:00
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src');
|
|
|
|
|
2013-02-19 14:23:43 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
|
|
|
|
file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_3');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('main2', $this->vendorDir.'/composer');
|
2013-11-26 01:53:44 +00:00
|
|
|
$this->assertAutoloadFiles('psr4_2', $this->vendorDir.'/composer', 'psr4');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('classmap2', $this->vendorDir.'/composer', 'classmap');
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:26:01 +00:00
|
|
|
public function testMainPackageAutoloadingWithTargetDir()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-04-19 19:26:01 +00:00
|
|
|
$package->setAutoload(array(
|
2012-04-19 20:04:49 +00:00
|
|
|
'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
|
2013-02-19 14:23:43 +00:00
|
|
|
'classmap' => array('Main/Foo/src', 'lib'),
|
|
|
|
'files' => array('foo.php', 'Main/Foo/bar.php'),
|
2012-04-19 19:26:01 +00:00
|
|
|
));
|
2012-04-19 20:04:49 +00:00
|
|
|
$package->setTargetDir('Main/Foo/');
|
2012-04-19 19:26:01 +00:00
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-04-19 19:26:01 +00:00
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a');
|
2013-02-19 14:23:43 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/lib');
|
|
|
|
|
|
|
|
file_put_contents($this->workingDir.'/src/rootfoo.php', '<?php class ClassMapFoo {}');
|
|
|
|
file_put_contents($this->workingDir.'/lib/rootbar.php', '<?php class ClassMapBar {}');
|
|
|
|
file_put_contents($this->workingDir.'/foo.php', '<?php class FilesFoo {}');
|
|
|
|
file_put_contents($this->workingDir.'/bar.php', '<?php class FilesBar {}');
|
2012-06-19 21:15:42 +00:00
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'TargetDir');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_target_dir.php', $this->vendorDir.'/autoload.php');
|
2012-11-10 20:54:23 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_real.php');
|
2013-07-23 11:48:55 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_target_dir.php', $this->vendorDir.'/composer/autoload_files.php');
|
2013-02-19 14:23:43 +00:00
|
|
|
$this->assertAutoloadFiles('classmap6', $this->vendorDir.'/composer', 'classmap');
|
2012-08-24 21:11:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 22:20:06 +00:00
|
|
|
public function testVendorsAutoloading()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2011-12-03 22:20:06 +00:00
|
|
|
|
|
|
|
$packages = array();
|
2012-08-23 13:52:40 +00:00
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
2012-05-14 12:01:37 +00:00
|
|
|
$packages[] = $c = new AliasPackage($b, '1.2', '1.2');
|
2011-12-03 22:20:06 +00:00
|
|
|
$a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/')));
|
|
|
|
$b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/')));
|
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2011-12-03 22:20:06 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
|
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('vendors', $this->vendorDir.'/composer');
|
|
|
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated, even if empty.");
|
2012-03-05 13:10:01 +00:00
|
|
|
}
|
|
|
|
|
2014-01-03 15:31:05 +00:00
|
|
|
public function testPSRToClassMapIgnoresNonExistingDir()
|
2012-11-27 13:23:10 +00:00
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
|
2014-01-03 15:31:05 +00:00
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array('Prefix' => 'foo/bar/non/existing/'),
|
|
|
|
'psr-4' => array('Prefix\\' => 'foo/bar/non/existing2/')
|
|
|
|
));
|
2012-11-27 13:23:10 +00:00
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-11-27 13:23:10 +00:00
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
|
|
|
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
|
|
|
$this->assertEquals(
|
|
|
|
array(),
|
|
|
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-03-05 13:10:01 +00:00
|
|
|
public function testVendorsClassMapAutoloading()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-03-05 13:10:01 +00:00
|
|
|
|
|
|
|
$packages = array();
|
2012-08-23 13:52:40 +00:00
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
2012-03-05 13:10:01 +00:00
|
|
|
$a->setAutoload(array('classmap' => array('src/')));
|
2012-07-18 16:40:17 +00:00
|
|
|
$b->setAutoload(array('classmap' => array('src/', 'lib/')));
|
2012-03-05 13:10:01 +00:00
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-03-05 13:10:01 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/lib');
|
2012-03-05 13:10:01 +00:00
|
|
|
file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
|
|
|
|
file_put_contents($this->vendorDir.'/b/b/src/b.php', '<?php class ClassMapBar {}');
|
|
|
|
file_put_contents($this->vendorDir.'/b/b/lib/c.php', '<?php class ClassMapBaz {}');
|
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_6');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
2012-03-10 00:59:59 +00:00
|
|
|
$this->assertEquals(
|
2013-03-14 09:23:35 +00:00
|
|
|
array(
|
2012-11-10 20:54:23 +00:00
|
|
|
'ClassMapBar' => $this->vendorDir.'/b/b/src/b.php',
|
|
|
|
'ClassMapBaz' => $this->vendorDir.'/b/b/lib/c.php',
|
|
|
|
'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
|
2013-03-14 09:23:35 +00:00
|
|
|
),
|
|
|
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
2012-03-05 13:10:01 +00:00
|
|
|
);
|
2012-07-18 16:40:17 +00:00
|
|
|
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/composer', 'classmap');
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
|
|
|
|
2013-02-19 14:23:43 +00:00
|
|
|
public function testVendorsClassMapAutoloadingWithTargetDir()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
|
|
|
|
$packages = array();
|
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
|
|
|
$a->setAutoload(array('classmap' => array('target/src/', 'lib/')));
|
|
|
|
$a->setTargetDir('target');
|
|
|
|
$b->setAutoload(array('classmap' => array('src/')));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2013-02-19 14:23:43 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/target/lib');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
|
|
|
|
file_put_contents($this->vendorDir.'/a/a/target/src/a.php', '<?php class ClassMapFoo {}');
|
|
|
|
file_put_contents($this->vendorDir.'/a/a/target/lib/b.php', '<?php class ClassMapBar {}');
|
|
|
|
file_put_contents($this->vendorDir.'/b/b/src/c.php', '<?php class ClassMapBaz {}');
|
|
|
|
|
|
|
|
$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->assertEquals(
|
2013-03-14 09:23:35 +00:00
|
|
|
array(
|
2013-02-19 14:23:43 +00:00
|
|
|
'ClassMapBar' => $this->vendorDir.'/a/a/target/lib/b.php',
|
|
|
|
'ClassMapBaz' => $this->vendorDir.'/b/b/src/c.php',
|
|
|
|
'ClassMapFoo' => $this->vendorDir.'/a/a/target/src/a.php',
|
2013-03-14 09:23:35 +00:00
|
|
|
),
|
|
|
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
2013-02-19 14:23:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-01 18:23:47 +00:00
|
|
|
public function testClassMapAutoloadingEmptyDirAndExactFile()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-04-01 18:23:47 +00:00
|
|
|
|
|
|
|
$packages = array();
|
2012-08-23 13:52:40 +00:00
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
|
|
|
$packages[] = $c = new Package('c/c', '1.0', '1.0');
|
2012-04-01 18:23:47 +00:00
|
|
|
$a->setAutoload(array('classmap' => array('')));
|
|
|
|
$b->setAutoload(array('classmap' => array('test.php')));
|
|
|
|
$c->setAutoload(array('classmap' => array('./')));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-04-01 18:23:47 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo');
|
2012-04-01 18:23:47 +00:00
|
|
|
file_put_contents($this->vendorDir.'/a/a/src/a.php', '<?php class ClassMapFoo {}');
|
|
|
|
file_put_contents($this->vendorDir.'/b/b/test.php', '<?php class ClassMapBar {}');
|
|
|
|
file_put_contents($this->vendorDir.'/c/c/foo/test.php', '<?php class ClassMapBaz {}');
|
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
2012-04-01 18:23:47 +00:00
|
|
|
$this->assertEquals(
|
2013-03-14 09:23:35 +00:00
|
|
|
array(
|
2012-11-10 20:54:23 +00:00
|
|
|
'ClassMapBar' => $this->vendorDir.'/b/b/test.php',
|
|
|
|
'ClassMapBaz' => $this->vendorDir.'/c/c/foo/test.php',
|
|
|
|
'ClassMapFoo' => $this->vendorDir.'/a/a/src/a.php',
|
2013-03-14 09:23:35 +00:00
|
|
|
),
|
|
|
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
2012-04-01 18:23:47 +00:00
|
|
|
);
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
|
2015-01-05 19:05:17 +00:00
|
|
|
$this->assertNotContains('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
|
2015-01-04 00:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testClassMapAutoloadingAuthoritative()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
|
|
|
|
$packages = array();
|
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
|
|
|
$packages[] = $c = new Package('c/c', '1.0', '1.0');
|
2015-08-16 19:56:52 +00:00
|
|
|
$a->setAutoload(array('psr-4' => array('' => 'src/')));
|
|
|
|
$b->setAutoload(array('psr-4' => array('' => './')));
|
|
|
|
$c->setAutoload(array('psr-4' => array('' => 'foo/')));
|
2015-01-04 00:35:25 +00:00
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
|
|
|
->method('getCanonicalPackages')
|
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo');
|
2015-08-16 19:56:52 +00:00
|
|
|
file_put_contents($this->vendorDir.'/a/a/src/ClassMapFoo.php', '<?php class ClassMapFoo {}');
|
|
|
|
file_put_contents($this->vendorDir.'/b/b/ClassMapBar.php', '<?php class ClassMapBar {}');
|
|
|
|
file_put_contents($this->vendorDir.'/c/c/foo/ClassMapBaz.php', '<?php class ClassMapBaz {}');
|
2015-01-04 00:35:25 +00:00
|
|
|
|
2015-08-16 19:56:52 +00:00
|
|
|
$this->generator->setClassMapAuthoritative(true);
|
2015-01-04 00:35:25 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_7');
|
2015-08-16 19:56:52 +00:00
|
|
|
|
2015-01-04 00:35:25 +00:00
|
|
|
$this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
2015-08-16 19:56:52 +00:00
|
|
|
'ClassMapBar' => $this->vendorDir.'/b/b/ClassMapBar.php',
|
|
|
|
'ClassMapBaz' => $this->vendorDir.'/c/c/foo/ClassMapBaz.php',
|
|
|
|
'ClassMapFoo' => $this->vendorDir.'/a/a/src/ClassMapFoo.php',
|
2015-01-04 00:35:25 +00:00
|
|
|
),
|
|
|
|
include $this->vendorDir.'/composer/autoload_classmap.php'
|
|
|
|
);
|
2015-08-16 19:56:52 +00:00
|
|
|
$this->assertAutoloadFiles('classmap8', $this->vendorDir.'/composer', 'classmap');
|
2015-01-04 00:35:25 +00:00
|
|
|
|
2015-01-05 19:05:17 +00:00
|
|
|
$this->assertContains('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
|
2012-04-01 18:23:47 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 16:18:33 +00:00
|
|
|
public function testFilesAutoloadGeneration()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-08-18 12:58:55 +00:00
|
|
|
$package->setAutoload(array('files' => array('root.php')));
|
2012-06-02 16:18:33 +00:00
|
|
|
|
|
|
|
$packages = array();
|
2012-08-23 13:52:40 +00:00
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
2013-01-31 22:39:57 +00:00
|
|
|
$packages[] = $c = new Package('c/c', '1.0', '1.0');
|
2012-06-02 16:18:33 +00:00
|
|
|
$a->setAutoload(array('files' => array('test.php')));
|
|
|
|
$b->setAutoload(array('files' => array('test2.php')));
|
2013-01-31 22:39:57 +00:00
|
|
|
$c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
|
|
|
|
$c->setTargetDir('foo/bar');
|
2012-06-02 16:18:33 +00:00
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-06-02 16:18:33 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b');
|
2013-01-31 22:39:57 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/foo/bar');
|
2012-06-02 16:18:33 +00:00
|
|
|
file_put_contents($this->vendorDir.'/a/a/test.php', '<?php function testFilesAutoloadGeneration1() {}');
|
|
|
|
file_put_contents($this->vendorDir.'/b/b/test2.php', '<?php function testFilesAutoloadGeneration2() {}');
|
2013-01-31 22:39:57 +00:00
|
|
|
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() {}');
|
2012-08-18 12:58:55 +00:00
|
|
|
file_put_contents($this->workingDir.'/root.php', '<?php function testFilesAutoloadGenerationRoot() {}');
|
2012-06-02 16:18:33 +00:00
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoload');
|
2012-06-11 12:15:08 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
|
2012-11-10 20:54:23 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php');
|
2013-07-23 11:48:55 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
|
2012-08-14 17:13:39 +00:00
|
|
|
|
2012-06-02 16:18:33 +00:00
|
|
|
include $this->vendorDir . '/autoload.php';
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
|
2013-01-31 22:39:57 +00:00
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration3'));
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration4'));
|
2012-08-18 12:58:55 +00:00
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
|
2012-06-02 16:18:33 +00:00
|
|
|
}
|
|
|
|
|
2015-08-15 08:12:16 +00:00
|
|
|
public function testFilesAutoloadGenerationRemoveExtraEntitiesFromAutoloadFiles()
|
|
|
|
{
|
|
|
|
$autoloadPackage = new Package('a', '1.0', '1.0');
|
|
|
|
$autoloadPackage->setAutoload(array('files' => array('root.php')));
|
2015-08-19 07:08:27 +00:00
|
|
|
$autoloadPackage->setIncludePaths(array('/lib', '/src'));
|
2015-08-15 08:12:16 +00:00
|
|
|
|
|
|
|
$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')));
|
2015-08-19 07:08:27 +00:00
|
|
|
$a->setIncludePaths(array('lib1', 'src1'));
|
2015-08-15 08:12:16 +00:00
|
|
|
$b->setAutoload(array('files' => array('test2.php')));
|
2015-08-19 07:08:27 +00:00
|
|
|
$b->setIncludePaths(array('lib2'));
|
2015-08-15 08:12:16 +00:00
|
|
|
$c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php')));
|
2015-08-19 07:08:27 +00:00
|
|
|
$c->setIncludePaths(array('lib3'));
|
2015-08-15 08:12:16 +00:00
|
|
|
$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');
|
2015-08-19 07:08:27 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php');
|
2015-08-15 08:12:16 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php');
|
2015-08-19 07:08:27 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions.php', $this->vendorDir.'/composer/include_paths.php');
|
2015-08-15 08:12:16 +00:00
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
|
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
|
2015-08-19 07:08:27 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php');
|
2015-08-15 08:12:16 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions_with_removed_extra.php', $this->vendorDir.'/composer/autoload_files.php');
|
2015-08-19 07:08:27 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions_with_removed_extra.php', $this->vendorDir.'/composer/include_paths.php');
|
2015-08-15 08:12:16 +00:00
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $notAutoloadPackage, $this->im, 'composer', false, 'FilesAutoload');
|
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php');
|
2015-08-19 07:08:27 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php', $this->vendorDir.'/composer/autoload_real.php');
|
2015-08-15 08:12:16 +00:00
|
|
|
$this->assertFileNotExists($this->vendorDir.'/composer/autoload_files.php');
|
2015-08-19 07:08:27 +00:00
|
|
|
$this->assertFileNotExists($this->vendorDir.'/composer/include_paths.php');
|
2015-08-15 08:12:16 +00:00
|
|
|
}
|
|
|
|
|
2012-09-01 11:24:17 +00:00
|
|
|
public function testFilesAutoloadOrderByDependencies()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array('files' => array('root.php')));
|
2012-10-16 23:00:11 +00:00
|
|
|
$package->setRequires(array(new Link('a', 'z/foo')));
|
2012-12-14 14:01:48 +00:00
|
|
|
$package->setRequires(array(new Link('a', 'd/d')));
|
|
|
|
$package->setRequires(array(new Link('a', 'e/e')));
|
2012-09-01 11:24:17 +00:00
|
|
|
|
|
|
|
$packages = array();
|
2012-10-16 23:00:11 +00:00
|
|
|
$packages[] = $z = new Package('z/foo', '1.0', '1.0');
|
2012-09-01 11:24:17 +00:00
|
|
|
$packages[] = $b = new Package('b/bar', '1.0', '1.0');
|
2012-10-17 08:50:53 +00:00
|
|
|
$packages[] = $d = new Package('d/d', '1.0', '1.0');
|
2012-12-14 14:01:48 +00:00
|
|
|
$packages[] = $c = new Package('c/lorem', '1.0', '1.0');
|
2012-10-17 08:50:53 +00:00
|
|
|
$packages[] = $e = new Package('e/e', '1.0', '1.0');
|
2012-09-01 11:24:17 +00:00
|
|
|
|
2012-10-16 23:00:11 +00:00
|
|
|
$z->setAutoload(array('files' => array('testA.php')));
|
|
|
|
$z->setRequires(array(new Link('z/foo', 'c/lorem')));
|
2012-09-01 11:24:17 +00:00
|
|
|
|
|
|
|
$b->setAutoload(array('files' => array('testB.php')));
|
2012-12-14 14:01:48 +00:00
|
|
|
$b->setRequires(array(new Link('b/bar', 'c/lorem'), new Link('b/bar', 'd/d')));
|
2012-09-01 11:24:17 +00:00
|
|
|
|
|
|
|
$c->setAutoload(array('files' => array('testC.php')));
|
|
|
|
|
2012-10-17 08:50:53 +00:00
|
|
|
$d->setAutoload(array('files' => array('testD.php')));
|
2012-12-14 14:01:48 +00:00
|
|
|
$d->setRequires(array(new Link('d/d', 'c/lorem')));
|
2012-10-17 08:50:53 +00:00
|
|
|
|
|
|
|
$e->setAutoload(array('files' => array('testE.php')));
|
|
|
|
$e->setRequires(array(new Link('e/e', 'c/lorem')));
|
|
|
|
|
2012-09-01 11:24:17 +00:00
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-09-01 11:24:17 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-10-16 23:00:11 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir . '/z/foo');
|
2012-09-01 11:24:17 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir . '/b/bar');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir . '/c/lorem');
|
2012-10-17 08:50:53 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir . '/d/d');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir . '/e/e');
|
2012-10-16 23:00:11 +00:00
|
|
|
file_put_contents($this->vendorDir . '/z/foo/testA.php', '<?php function testFilesAutoloadOrderByDependency1() {}');
|
2012-09-01 11:24:17 +00:00
|
|
|
file_put_contents($this->vendorDir . '/b/bar/testB.php', '<?php function testFilesAutoloadOrderByDependency2() {}');
|
|
|
|
file_put_contents($this->vendorDir . '/c/lorem/testC.php', '<?php function testFilesAutoloadOrderByDependency3() {}');
|
2012-10-17 08:50:53 +00:00
|
|
|
file_put_contents($this->vendorDir . '/d/d/testD.php', '<?php function testFilesAutoloadOrderByDependency4() {}');
|
|
|
|
file_put_contents($this->vendorDir . '/e/e/testE.php', '<?php function testFilesAutoloadOrderByDependency5() {}');
|
2012-09-01 11:24:17 +00:00
|
|
|
file_put_contents($this->workingDir . '/root.php', '<?php function testFilesAutoloadOrderByDependencyRoot() {}');
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoloadOrder');
|
|
|
|
$this->assertFileEquals(__DIR__ . '/Fixtures/autoload_functions_by_dependency.php', $this->vendorDir . '/autoload.php');
|
2012-11-10 20:54:23 +00:00
|
|
|
$this->assertFileEquals(__DIR__ . '/Fixtures/autoload_real_files_by_dependency.php', $this->vendorDir . '/composer/autoload_real.php');
|
2012-09-01 11:24:17 +00:00
|
|
|
|
2012-11-10 20:54:23 +00:00
|
|
|
require $this->vendorDir . '/autoload.php';
|
2012-09-01 11:24:17 +00:00
|
|
|
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadOrderByDependency1'));
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadOrderByDependency2'));
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadOrderByDependency3'));
|
2012-10-17 08:50:53 +00:00
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadOrderByDependency4'));
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadOrderByDependency5'));
|
2012-09-01 11:24:17 +00:00
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadOrderByDependencyRoot'));
|
|
|
|
}
|
|
|
|
|
2014-01-07 23:05:24 +00:00
|
|
|
/**
|
|
|
|
* Test that PSR-0 and PSR-4 mappings are processed in the correct order for
|
|
|
|
* autoloading and for classmap generation:
|
|
|
|
* - The main package has priority over other packages.
|
|
|
|
* - Longer namespaces have priority over shorter namespaces.
|
|
|
|
*/
|
2012-01-13 03:14:30 +00:00
|
|
|
public function testOverrideVendorsAutoloading()
|
|
|
|
{
|
2013-12-22 21:00:26 +00:00
|
|
|
$mainPackage = new Package('z', '1.0', '1.0');
|
|
|
|
$mainPackage->setAutoload(array(
|
2013-12-22 20:34:31 +00:00
|
|
|
'psr-0' => array('A\\B' => $this->workingDir.'/lib'),
|
|
|
|
'classmap' => array($this->workingDir.'/src')
|
|
|
|
));
|
2013-12-22 21:00:26 +00:00
|
|
|
$mainPackage->setRequires(array(new Link('z', 'a/a')));
|
2012-01-13 03:14:30 +00:00
|
|
|
|
|
|
|
$packages = array();
|
2012-08-23 13:52:40 +00:00
|
|
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
|
|
|
$packages[] = $b = new Package('b/b', '1.0', '1.0');
|
2013-12-22 20:34:31 +00:00
|
|
|
$a->setAutoload(array(
|
|
|
|
'psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'),
|
|
|
|
'classmap' => array('classmap'),
|
|
|
|
));
|
|
|
|
$b->setAutoload(array(
|
|
|
|
'psr-0' => array('B\\Sub\\Name' => 'src/'),
|
|
|
|
));
|
2012-01-13 03:14:30 +00:00
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2012-01-13 03:14:30 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/lib/A/B');
|
2012-10-16 23:40:15 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src/');
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
2012-10-16 23:40:15 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/classmap');
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/lib/A/B');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src');
|
2014-01-07 23:05:24 +00:00
|
|
|
|
|
|
|
// Define the classes A\B\C and Foo\Bar in the main package.
|
2012-06-19 21:15:42 +00:00
|
|
|
file_put_contents($this->workingDir.'/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
|
2012-10-16 23:40:15 +00:00
|
|
|
file_put_contents($this->workingDir.'/src/classes.php', '<?php namespace Foo; class Bar {}');
|
2014-01-07 23:05:24 +00:00
|
|
|
|
|
|
|
// Define the same two classes in the package a/a.
|
2012-06-19 21:15:42 +00:00
|
|
|
file_put_contents($this->vendorDir.'/a/a/lib/A/B/C.php', '<?php namespace A\\B; class C {}');
|
2012-10-16 23:40:15 +00:00
|
|
|
file_put_contents($this->vendorDir.'/a/a/classmap/classes.php', '<?php namespace Foo; class Bar {}');
|
2012-06-19 21:15:42 +00:00
|
|
|
|
|
|
|
$expectedNamespace = <<<EOF
|
|
|
|
<?php
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_namespaces.php @generated by Composer
|
2012-06-19 21:15:42 +00:00
|
|
|
|
2013-03-27 17:45:27 +00:00
|
|
|
\$vendorDir = dirname(dirname(__FILE__));
|
2012-06-19 21:15:42 +00:00
|
|
|
\$baseDir = dirname(\$vendorDir);
|
|
|
|
|
|
|
|
return array(
|
2013-05-05 08:56:46 +00:00
|
|
|
'B\\\\Sub\\\\Name' => array(\$vendorDir . '/b/b/src'),
|
2013-03-14 09:23:35 +00:00
|
|
|
'A\\\\B' => array(\$baseDir . '/lib', \$vendorDir . '/a/a/lib'),
|
2013-05-05 08:56:46 +00:00
|
|
|
'A' => array(\$vendorDir . '/a/a/src'),
|
2012-06-19 21:15:42 +00:00
|
|
|
);
|
|
|
|
|
2013-12-22 18:38:11 +00:00
|
|
|
EOF;
|
|
|
|
|
|
|
|
// autoload_psr4.php is expected to be empty in this example.
|
|
|
|
$expectedPsr4 = <<<EOF
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_psr4.php @generated by Composer
|
|
|
|
|
|
|
|
\$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
\$baseDir = dirname(\$vendorDir);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
);
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
EOF;
|
|
|
|
|
|
|
|
$expectedClassmap = <<<EOF
|
|
|
|
<?php
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_classmap.php @generated by Composer
|
2012-06-19 21:15:42 +00:00
|
|
|
|
2013-03-27 17:45:27 +00:00
|
|
|
\$vendorDir = dirname(dirname(__FILE__));
|
2012-06-19 21:15:42 +00:00
|
|
|
\$baseDir = dirname(\$vendorDir);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'A\\\\B\\\\C' => \$baseDir . '/lib/A/B/C.php',
|
2012-10-16 23:40:15 +00:00
|
|
|
'Foo\\\\Bar' => \$baseDir . '/src/classes.php',
|
2012-06-19 21:15:42 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
|
2013-12-22 21:00:26 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $mainPackage, $this->im, 'composer', true, '_9');
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
|
2013-12-22 18:38:11 +00:00
|
|
|
$this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
|
2012-01-13 03:14:30 +00:00
|
|
|
}
|
|
|
|
|
2012-04-04 13:15:37 +00:00
|
|
|
public function testIncludePathFileGeneration()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-04-04 13:15:37 +00:00
|
|
|
$packages = array();
|
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
$a = new Package("a/a", "1.0", "1.0");
|
2012-04-04 13:15:37 +00:00
|
|
|
$a->setIncludePaths(array("lib/"));
|
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
$b = new Package("b/b", "1.0", "1.0");
|
2012-04-04 13:15:37 +00:00
|
|
|
$b->setIncludePaths(array("library"));
|
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
$c = new Package("c", "1.0", "1.0");
|
2012-04-19 08:51:57 +00:00
|
|
|
$c->setIncludePaths(array("library"));
|
|
|
|
|
2012-04-04 13:15:37 +00:00
|
|
|
$packages[] = $a;
|
|
|
|
$packages[] = $b;
|
2012-04-19 08:51:57 +00:00
|
|
|
$packages[] = $c;
|
2012-04-04 13:15:37 +00:00
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method("getCanonicalPackages")
|
2012-04-04 13:15:37 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
2012-04-04 13:15:37 +00:00
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_10');
|
2012-04-04 13:15:37 +00:00
|
|
|
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/include_paths.php', $this->vendorDir.'/composer/include_paths.php');
|
2012-04-04 13:15:37 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
2012-04-19 08:51:57 +00:00
|
|
|
$this->vendorDir."/a/a/lib",
|
|
|
|
$this->vendorDir."/b/b/library",
|
|
|
|
$this->vendorDir."/c/library",
|
2012-04-04 13:15:37 +00:00
|
|
|
),
|
2012-11-10 20:54:23 +00:00
|
|
|
require $this->vendorDir."/composer/include_paths.php"
|
2012-04-04 13:15:37 +00:00
|
|
|
);
|
|
|
|
}
|
2012-04-08 15:42:57 +00:00
|
|
|
|
2012-07-06 18:17:27 +00:00
|
|
|
public function testIncludePathsArePrependedInAutoloadFile()
|
2012-04-04 13:15:37 +00:00
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-04-04 13:15:37 +00:00
|
|
|
$packages = array();
|
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
$a = new Package("a/a", "1.0", "1.0");
|
2012-04-04 13:15:37 +00:00
|
|
|
$a->setIncludePaths(array("lib/"));
|
|
|
|
|
|
|
|
$packages[] = $a;
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method("getCanonicalPackages")
|
2012-04-04 13:15:37 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-04-22 20:11:03 +00:00
|
|
|
mkdir($this->vendorDir."/composer", 0777, true);
|
2012-04-04 13:15:37 +00:00
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_11');
|
2012-04-04 13:15:37 +00:00
|
|
|
|
|
|
|
$oldIncludePath = get_include_path();
|
|
|
|
|
2012-11-10 20:54:23 +00:00
|
|
|
require $this->vendorDir."/autoload.php";
|
2012-04-04 13:15:37 +00:00
|
|
|
|
|
|
|
$this->assertEquals(
|
2012-07-06 18:17:27 +00:00
|
|
|
$this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
|
2012-04-04 13:15:37 +00:00
|
|
|
get_include_path()
|
|
|
|
);
|
|
|
|
|
|
|
|
set_include_path($oldIncludePath);
|
|
|
|
}
|
|
|
|
|
2012-12-17 09:54:48 +00:00
|
|
|
public function testIncludePathsInMainPackage()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setIncludePaths(array('/lib', '/src'));
|
|
|
|
|
|
|
|
$packages = array($a = new Package("a/a", "1.0", "1.0"));
|
|
|
|
$a->setIncludePaths(array("lib/"));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method("getCanonicalPackages")
|
2012-12-17 09:54:48 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
|
|
|
mkdir($this->vendorDir."/composer", 0777, true);
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
|
|
|
|
|
|
|
|
$oldIncludePath = get_include_path();
|
|
|
|
|
|
|
|
require $this->vendorDir."/autoload.php";
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$this->workingDir."/lib".PATH_SEPARATOR.$this->workingDir."/src".PATH_SEPARATOR.$this->vendorDir."/a/a/lib".PATH_SEPARATOR.$oldIncludePath,
|
|
|
|
get_include_path()
|
|
|
|
);
|
|
|
|
|
|
|
|
set_include_path($oldIncludePath);
|
|
|
|
}
|
|
|
|
|
2012-04-08 15:42:57 +00:00
|
|
|
public function testIncludePathFileWithoutPathsIsSkipped()
|
2012-04-04 13:15:37 +00:00
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-04-04 13:15:37 +00:00
|
|
|
$packages = array();
|
|
|
|
|
2012-08-23 13:52:40 +00:00
|
|
|
$a = new Package("a/a", "1.0", "1.0");
|
2012-04-04 13:15:37 +00:00
|
|
|
$packages[] = $a;
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method("getCanonicalPackages")
|
2012-04-04 13:15:37 +00:00
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-04-22 20:11:03 +00:00
|
|
|
mkdir($this->vendorDir."/composer", 0777, true);
|
2012-04-04 13:15:37 +00:00
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, "composer", false, '_12');
|
2012-04-04 13:15:37 +00:00
|
|
|
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertFalse(file_exists($this->vendorDir."/composer/include_paths.php"));
|
2012-04-04 13:15:37 +00:00
|
|
|
}
|
2013-02-19 14:23:43 +00:00
|
|
|
|
2013-05-06 14:37:21 +00:00
|
|
|
public function testPreAndPostEventsAreDispatchedDuringAutoloadDump()
|
2013-01-06 19:34:52 +00:00
|
|
|
{
|
|
|
|
$this->eventDispatcher
|
2013-05-06 14:37:21 +00:00
|
|
|
->expects($this->at(0))
|
2013-08-14 15:42:11 +00:00
|
|
|
->method('dispatchScript')
|
2013-05-06 14:37:21 +00:00
|
|
|
->with(ScriptEvents::PRE_AUTOLOAD_DUMP, false);
|
|
|
|
|
|
|
|
$this->eventDispatcher
|
|
|
|
->expects($this->at(1))
|
2013-08-14 15:42:11 +00:00
|
|
|
->method('dispatchScript')
|
2013-01-06 19:34:52 +00:00
|
|
|
->with(ScriptEvents::POST_AUTOLOAD_DUMP, false);
|
|
|
|
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array('psr-0' => array('foo/bar/non/existing/')));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2013-01-06 19:34:52 +00:00
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_8');
|
|
|
|
}
|
2013-02-19 14:23:43 +00:00
|
|
|
|
|
|
|
public function testUseGlobalIncludePath()
|
2013-02-04 08:12:41 +00:00
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''),
|
|
|
|
));
|
|
|
|
$package->setTargetDir('Main/Foo/');
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2013-02-04 08:12:41 +00:00
|
|
|
->will($this->returnValue(array()));
|
2013-02-19 14:23:43 +00:00
|
|
|
|
2015-01-04 00:35:25 +00:00
|
|
|
$this->configValueMap['use-include-path'] = true;
|
2013-02-04 08:12:41 +00:00
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a');
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'IncludePath');
|
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_include_path.php', $this->vendorDir.'/composer/autoload_real.php');
|
|
|
|
}
|
2012-04-04 13:15:37 +00:00
|
|
|
|
2013-04-01 07:27:50 +00:00
|
|
|
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'),
|
2013-12-22 18:58:27 +00:00
|
|
|
'psr-4' => array('Acme\Foo\\' => 'src-psr4'),
|
2013-04-01 07:27:50 +00:00
|
|
|
'classmap' => array('classmap'),
|
|
|
|
'files' => array('test.php'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$vendorPackage = new Package('b/b', '1.0', '1.0');
|
|
|
|
$vendorPackage->setAutoload(array(
|
|
|
|
'psr-0' => array('Bar' => 'lib'),
|
2013-12-22 18:58:27 +00:00
|
|
|
'psr-4' => array('Acme\Bar\\' => 'lib-psr4'),
|
2013-04-01 07:27:50 +00:00
|
|
|
'classmap' => array('classmaps'),
|
|
|
|
'files' => array('bootstrap.php'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2013-04-01 07:27:50 +00:00
|
|
|
->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();
|
2013-06-13 11:28:24 +00:00
|
|
|
|
2013-04-01 07:27:50 +00:00
|
|
|
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
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_namespaces.php @generated by Composer
|
2013-04-01 07:27:50 +00:00
|
|
|
|
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir).'/working-dir';
|
|
|
|
|
|
|
|
return array(
|
2013-05-05 08:56:46 +00:00
|
|
|
'Foo' => array($baseDir . '/src'),
|
|
|
|
'Bar' => array($vendorDir . '/b/b/lib'),
|
2013-04-01 07:27:50 +00:00
|
|
|
);
|
|
|
|
|
2013-12-22 18:38:11 +00:00
|
|
|
EOF;
|
|
|
|
|
|
|
|
$expectedPsr4 = <<<'EOF'
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_psr4.php @generated by Composer
|
|
|
|
|
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir).'/working-dir';
|
|
|
|
|
|
|
|
return array(
|
2013-12-22 18:58:27 +00:00
|
|
|
'Acme\\Foo\\' => array($baseDir . '/src-psr4'),
|
|
|
|
'Acme\\Bar\\' => array($vendorDir . '/b/b/lib-psr4'),
|
2013-12-22 18:38:11 +00:00
|
|
|
);
|
|
|
|
|
2013-04-01 07:27:50 +00:00
|
|
|
EOF;
|
|
|
|
|
|
|
|
$expectedClassmap = <<<'EOF'
|
|
|
|
<?php
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_classmap.php @generated by Composer
|
2013-04-01 07:27:50 +00:00
|
|
|
|
|
|
|
$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'));
|
2013-12-22 18:38:11 +00:00
|
|
|
$this->assertEquals($expectedPsr4, file_get_contents($vendorDir.'/composer/autoload_psr4.php'));
|
2013-04-01 07:27:50 +00:00
|
|
|
$this->assertEquals($expectedClassmap, file_get_contents($vendorDir.'/composer/autoload_classmap.php'));
|
2013-08-01 13:42:30 +00:00
|
|
|
$this->assertContains("\n \$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
|
|
|
|
$this->assertContains("\n \$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
|
2013-04-01 07:27:50 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 12:22:16 +00:00
|
|
|
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(
|
2013-04-07 09:34:58 +00:00
|
|
|
'psr-0' => array('Foo' => '../path/../src'),
|
2013-12-22 18:58:27 +00:00
|
|
|
'psr-4' => array('Acme\Foo\\' => '../path/../src-psr4'),
|
2013-04-07 09:34:58 +00:00
|
|
|
'classmap' => array('../classmap'),
|
|
|
|
'files' => array('../test.php'),
|
2013-04-05 12:22:16 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2013-04-07 09:34:58 +00:00
|
|
|
->will($this->returnValue(array()));
|
2013-04-05 12:22:16 +00:00
|
|
|
|
|
|
|
$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
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_namespaces.php @generated by Composer
|
2013-04-05 12:22:16 +00:00
|
|
|
|
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir).'/working-dir';
|
|
|
|
|
|
|
|
return array(
|
2013-05-05 08:56:46 +00:00
|
|
|
'Foo' => array($baseDir . '/../src'),
|
2013-04-05 12:22:16 +00:00
|
|
|
);
|
|
|
|
|
2013-12-22 18:38:11 +00:00
|
|
|
EOF;
|
|
|
|
|
|
|
|
$expectedPsr4 = <<<'EOF'
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_psr4.php @generated by Composer
|
|
|
|
|
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir).'/working-dir';
|
|
|
|
|
|
|
|
return array(
|
2013-12-22 18:58:27 +00:00
|
|
|
'Acme\\Foo\\' => array($baseDir . '/../src-psr4'),
|
2013-12-22 18:38:11 +00:00
|
|
|
);
|
|
|
|
|
2013-04-05 12:22:16 +00:00
|
|
|
EOF;
|
|
|
|
|
2013-12-22 18:39:09 +00:00
|
|
|
$expectedClassmap = <<<'EOF'
|
2013-04-05 12:22:16 +00:00
|
|
|
<?php
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_classmap.php @generated by Composer
|
2013-04-05 12:22:16 +00:00
|
|
|
|
|
|
|
$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'));
|
2013-12-22 18:38:11 +00:00
|
|
|
$this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
|
2013-04-05 12:22:16 +00:00
|
|
|
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
|
2013-08-01 13:42:30 +00:00
|
|
|
$this->assertContains("\n \$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
|
2013-04-05 12:22:16 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 09:34:58 +00:00
|
|
|
public function testEmptyPaths()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array('Foo' => ''),
|
2013-12-22 18:58:27 +00:00
|
|
|
'psr-4' => array('Acme\Foo\\' => ''),
|
2013-04-07 09:34:58 +00:00
|
|
|
'classmap' => array(''),
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
2013-04-28 20:32:46 +00:00
|
|
|
->method('getCanonicalPackages')
|
2013-04-07 09:34:58 +00:00
|
|
|
->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
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_namespaces.php @generated by Composer
|
2013-04-07 09:34:58 +00:00
|
|
|
|
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir);
|
|
|
|
|
|
|
|
return array(
|
2013-05-05 08:56:46 +00:00
|
|
|
'Foo' => array($baseDir . '/'),
|
2013-04-07 09:34:58 +00:00
|
|
|
);
|
|
|
|
|
2013-12-22 18:38:11 +00:00
|
|
|
EOF;
|
|
|
|
|
2013-12-22 18:58:27 +00:00
|
|
|
$expectedPsr4 = <<<'EOF'
|
2013-12-22 18:38:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_psr4.php @generated by Composer
|
|
|
|
|
2013-12-22 18:58:27 +00:00
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir);
|
2013-12-22 18:38:11 +00:00
|
|
|
|
|
|
|
return array(
|
2013-12-22 18:58:27 +00:00
|
|
|
'Acme\\Foo\\' => array($baseDir . '/'),
|
2013-12-22 18:38:11 +00:00
|
|
|
);
|
|
|
|
|
2013-04-07 09:34:58 +00:00
|
|
|
EOF;
|
|
|
|
|
2013-12-22 18:39:09 +00:00
|
|
|
$expectedClassmap = <<<'EOF'
|
2013-04-07 09:34:58 +00:00
|
|
|
<?php
|
|
|
|
|
2013-08-27 23:08:38 +00:00
|
|
|
// autoload_classmap.php @generated by Composer
|
2013-04-07 09:34:58 +00:00
|
|
|
|
|
|
|
$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'));
|
2013-12-22 18:38:11 +00:00
|
|
|
$this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
|
2013-04-07 09:34:58 +00:00
|
|
|
$this->assertEquals($expectedClassmap, file_get_contents($this->vendorDir.'/composer/autoload_classmap.php'));
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:34:41 +00:00
|
|
|
public function testVendorSubstringPath()
|
|
|
|
{
|
|
|
|
$package = new Package('a', '1.0', '1.0');
|
|
|
|
$package->setAutoload(array(
|
|
|
|
'psr-0' => array('Foo' => 'composer-test-autoload-src/src'),
|
2013-12-22 18:58:27 +00:00
|
|
|
'psr-4' => array('Acme\Foo\\' => 'composer-test-autoload-src/src-psr4'),
|
2013-09-26 12:34:41 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
|
|
|
->method('getCanonicalPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a');
|
|
|
|
|
|
|
|
$expectedNamespace = <<<'EOF'
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_namespaces.php @generated by Composer
|
|
|
|
|
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'Foo' => array($baseDir . '/composer-test-autoload-src/src'),
|
|
|
|
);
|
|
|
|
|
2013-12-22 18:38:11 +00:00
|
|
|
EOF;
|
|
|
|
|
2013-12-22 18:58:27 +00:00
|
|
|
$expectedPsr4 = <<<'EOF'
|
2013-12-22 18:38:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_psr4.php @generated by Composer
|
|
|
|
|
2013-12-22 18:58:27 +00:00
|
|
|
$vendorDir = dirname(dirname(__FILE__));
|
|
|
|
$baseDir = dirname($vendorDir);
|
2013-12-22 18:38:11 +00:00
|
|
|
|
|
|
|
return array(
|
2013-12-22 18:58:27 +00:00
|
|
|
'Acme\\Foo\\' => array($baseDir . '/composer-test-autoload-src/src-psr4'),
|
2013-12-22 18:38:11 +00:00
|
|
|
);
|
|
|
|
|
2013-09-26 12:34:41 +00:00
|
|
|
EOF;
|
|
|
|
|
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'VendorSubstring');
|
|
|
|
$this->assertEquals($expectedNamespace, file_get_contents($this->vendorDir.'/composer/autoload_namespaces.php'));
|
2013-12-22 18:38:11 +00:00
|
|
|
$this->assertEquals($expectedPsr4, file_get_contents($this->vendorDir.'/composer/autoload_psr4.php'));
|
2013-09-26 12:34:41 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 12:58:35 +00:00
|
|
|
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
|
2011-12-03 22:20:06 +00:00
|
|
|
{
|
2012-11-10 20:54:23 +00:00
|
|
|
$a = __DIR__.'/Fixtures/autoload_'.$name.'.php';
|
|
|
|
$b = $dir.'/autoload_'.$type.'.php';
|
2013-03-14 09:23:35 +00:00
|
|
|
$this->assertFileEquals($a, $b);
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
2015-05-28 13:42:19 +00:00
|
|
|
|
|
|
|
public static function assertFileEquals($expected, $actual, $message = '', $canonicalize = false, $ignoreCase = false)
|
|
|
|
{
|
|
|
|
return self::assertEquals(
|
|
|
|
file_get_contents($expected),
|
|
|
|
file_get_contents($actual),
|
|
|
|
$message ?: $expected.' equals '.$actual,
|
|
|
|
0,
|
|
|
|
10,
|
|
|
|
$canonicalize,
|
|
|
|
$ignoreCase
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function assertEquals($expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
|
|
|
|
{
|
|
|
|
return parent::assertEquals(str_replace("\r", '', $expected), str_replace("\r", '', $actual), $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
|
|
|
|
}
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|