1
0
Fork 0

Add support for files in classmap autoload config, fixes #463

pull/520/head
Jordi Boggiano 2012-04-01 20:23:47 +02:00
parent 1fe24a3837
commit 2d9739bd05
3 changed files with 54 additions and 1 deletions

View File

@ -47,7 +47,11 @@ class ClassMapGenerator
static public function createMap($dir)
{
if (is_string($dir)) {
$dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
if (is_file($dir)) {
$dir = array(new \SplFileInfo($dir));
} else {
$dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
}
}
$map = array();

View File

@ -196,6 +196,43 @@ class AutoloadGeneratorTest extends TestCase
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/.composer', 'classmap');
}
public function testClassMapAutoloadingEmptyDirAndExactFile()
{
$package = new MemoryPackage('a', '1.0', '1.0');
$packages = array();
$packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0');
$packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0');
$packages[] = $c = new MemoryPackage('c/c', '1.0', '1.0');
$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));
@mkdir($this->vendorDir.'/.composer', 0777, true);
mkdir($this->vendorDir.'/a/a/src', 0777, true);
mkdir($this->vendorDir.'/b/b', 0777, true);
mkdir($this->vendorDir.'/c/c/foo', 0777, true);
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 {}');
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
$this->assertTrue(file_exists($this->vendorDir.'/.composer/autoload_classmap.php'), "ClassMap file needs to be generated.");
$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',
),
include ($this->vendorDir.'/.composer/autoload_classmap.php')
);
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/.composer', 'classmap');
}
public function testOverrideVendorsAutoloading()
{
$package = new MemoryPackage('a', '1.0', '1.0');

View File

@ -0,0 +1,12 @@
<?php
// autoload_classmap.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'ClassMapFoo' => $baseDir . '/composer-test-autoload/a/a/src/a.php',
'ClassMapBar' => $baseDir . '/composer-test-autoload/b/b/test.php',
'ClassMapBaz' => $baseDir . '/composer-test-autoload/c/c/foo/test.php',
);