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-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;
|
2012-02-24 11:28:41 +00:00
|
|
|
use Composer\Test\TestCase;
|
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
|
|
|
{
|
|
|
|
public $vendorDir;
|
2012-06-24 19:58:51 +00:00
|
|
|
private $config;
|
2011-12-03 22:20:06 +00:00
|
|
|
private $workingDir;
|
|
|
|
private $im;
|
|
|
|
private $repository;
|
|
|
|
private $generator;
|
2012-02-24 09:40:47 +00:00
|
|
|
private $fs;
|
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;
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest';
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir);
|
2011-12-03 22:20:06 +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');
|
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('get')
|
|
|
|
->with($this->equalTo('vendor-dir'))
|
|
|
|
->will($this->returnCallback(function () use ($that) {
|
|
|
|
return $that->vendorDir;
|
|
|
|
}));
|
|
|
|
|
2011-12-03 22:20:06 +00:00
|
|
|
$this->dir = getcwd();
|
|
|
|
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) {
|
|
|
|
return $that->vendorDir.'/'.$package->getName();
|
|
|
|
}));
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->repository = $this->getMock('Composer\Repository\RepositoryInterface');
|
2011-12-03 22:20:06 +00:00
|
|
|
|
|
|
|
$this->generator = new AutoloadGenerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
2012-06-19 21:15:42 +00:00
|
|
|
chdir($this->dir);
|
|
|
|
|
|
|
|
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(
|
2012-03-28 15:09:07 +00:00
|
|
|
'psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')),
|
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())
|
2011-12-03 22:20:06 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/composer');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/src');
|
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/lib');
|
2012-03-21 12:58:35 +00:00
|
|
|
|
|
|
|
$this->createClassFile($this->workingDir);
|
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_1');
|
2012-04-22 20:11:03 +00:00
|
|
|
$this->assertAutoloadFiles('main', $this->vendorDir.'/composer');
|
|
|
|
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
|
2011-12-03 22:20: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/'),
|
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())
|
2012-02-02 15:38:48 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->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
|
|
|
|
2012-03-21 12:58:35 +00:00
|
|
|
$this->createClassFile($this->vendorDir);
|
|
|
|
|
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');
|
|
|
|
$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/'),
|
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())
|
2011-12-03 22:20:06 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->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');
|
|
|
|
|
2012-03-21 12:58:35 +00:00
|
|
|
$this->createClassFile($this->workingDir);
|
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');
|
|
|
|
$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' => ''),
|
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())
|
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/a');
|
|
|
|
|
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-08-06 08:56:57 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_target_dir.php', $this->vendorDir.'/composer/autoload_realTargetDir.php');
|
2012-04-19 19:26:01 +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())
|
2011-12-03 22:20:06 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->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
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
->method('getPackages')
|
|
|
|
->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(
|
|
|
|
array(
|
|
|
|
'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php',
|
|
|
|
'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/src/b.php',
|
|
|
|
'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/b/b/lib/c.php',
|
2012-03-05 13:10:01 +00:00
|
|
|
),
|
2012-04-22 20:11:03 +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
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
->method('getPackages')
|
|
|
|
->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(
|
|
|
|
array(
|
|
|
|
'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php',
|
|
|
|
'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/test.php',
|
|
|
|
'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/c/c/foo/test.php',
|
|
|
|
),
|
2012-04-22 20:11:03 +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');
|
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');
|
2012-06-02 16:18:33 +00:00
|
|
|
$a->setAutoload(array('files' => array('test.php')));
|
|
|
|
$b->setAutoload(array('files' => array('test2.php')));
|
|
|
|
|
|
|
|
$this->repository->expects($this->once())
|
|
|
|
->method('getPackages')
|
|
|
|
->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');
|
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() {}');
|
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-08-06 08:56:57 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_realFilesAutoload.php');
|
2012-06-02 16:18:33 +00:00
|
|
|
|
2012-08-14 17:13:39 +00:00
|
|
|
// suppress the class loader to avoid fatals if the class is redefined
|
|
|
|
file_put_contents($this->vendorDir.'/composer/ClassLoader.php', '');
|
|
|
|
|
2012-06-02 16:18:33 +00:00
|
|
|
include $this->vendorDir . '/autoload.php';
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration1'));
|
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGeneration2'));
|
2012-08-18 12:58:55 +00:00
|
|
|
$this->assertTrue(function_exists('testFilesAutoloadGenerationRoot'));
|
2012-06-02 16:18:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 03:14:30 +00:00
|
|
|
public function testOverrideVendorsAutoloading()
|
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
$package = new Package('a', '1.0', '1.0');
|
2012-06-19 21:15:42 +00:00
|
|
|
$package->setAutoload(array('psr-0' => array('A\\B' => $this->workingDir.'/lib')));
|
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');
|
2012-01-13 03:14:30 +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())
|
2012-01-13 03:14:30 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue($packages));
|
|
|
|
|
2012-06-19 21:15:42 +00:00
|
|
|
$this->fs->ensureDirectoryExists($this->workingDir.'/lib/A/B');
|
|
|
|
$this->fs->ensureDirectoryExists($this->vendorDir.'/composer');
|
|
|
|
$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');
|
|
|
|
file_put_contents($this->workingDir.'/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 {}');
|
|
|
|
|
|
|
|
$workDir = strtr($this->workingDir, '\\', '/');
|
|
|
|
$expectedNamespace = <<<EOF
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_namespaces.php generated by Composer
|
|
|
|
|
|
|
|
\$vendorDir = dirname(__DIR__);
|
|
|
|
\$baseDir = dirname(\$vendorDir);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'B\\\\Sub\\\\Name' => \$vendorDir . '/b/b/src/',
|
|
|
|
'A\\\\B' => array('$workDir/lib', \$vendorDir . '/a/a/lib/'),
|
|
|
|
'A' => \$vendorDir . '/a/a/src/',
|
|
|
|
);
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
|
|
|
|
$expectedClassmap = <<<EOF
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// autoload_classmap.php generated by Composer
|
|
|
|
|
|
|
|
\$vendorDir = dirname(__DIR__);
|
|
|
|
\$baseDir = dirname(\$vendorDir);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'A\\\\B\\\\C' => \$baseDir . '/lib/A/B/C.php',
|
|
|
|
);
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
|
2012-08-14 18:28:49 +00:00
|
|
|
$this->generator->dump($this->config, $this->repository, $package, $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'));
|
|
|
|
$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())
|
|
|
|
->method("getPackages")
|
|
|
|
->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-04-22 20:11:03 +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())
|
|
|
|
->method("getPackages")
|
|
|
|
->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-08-14 17:13:39 +00:00
|
|
|
// suppress the class loader to avoid fatals if the class is redefined
|
|
|
|
file_put_contents($this->vendorDir.'/composer/ClassLoader.php', '');
|
|
|
|
|
2012-04-22 20:11:03 +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-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())
|
|
|
|
->method("getPackages")
|
|
|
|
->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
|
|
|
}
|
|
|
|
|
2012-03-21 12:58:35 +00:00
|
|
|
private function createClassFile($basedir)
|
|
|
|
{
|
2012-04-22 20:11:03 +00:00
|
|
|
if (!is_dir($basedir.'/composersrc')) {
|
|
|
|
mkdir($basedir.'/composersrc', 0777, true);
|
2012-03-21 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 20:11:03 +00:00
|
|
|
file_put_contents($basedir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
|
2012-03-21 12:58:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
|
2011-12-03 22:20:06 +00:00
|
|
|
{
|
2012-03-21 12:58:35 +00:00
|
|
|
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_'.$name.'.php', $dir.'/autoload_'.$type.'.php');
|
2011-12-03 22:20:06 +00:00
|
|
|
}
|
|
|
|
}
|