1
0
Fork 0

Added test for generated classmap files

pull/484/head
Martin Hasoň 2012-03-21 13:58:35 +01:00
parent 81e8261692
commit fde38dacec
5 changed files with 82 additions and 6 deletions

View File

@ -66,21 +66,34 @@ class AutoloadGeneratorTest extends TestCase
} elseif (is_dir($this->vendorDir)) {
$this->fs->removeDirectory($this->vendorDir);
}
if (is_dir($this->workingDir.'/.composersrc')) {
$this->fs->removeDirectory($this->workingDir.'/.composersrc');
}
chdir($this->dir);
}
public function testMainPackageAutoloading()
{
$package = new MemoryPackage('a', '1.0', '1.0');
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
$package->setAutoload(array(
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
'classmap' => array('.composersrc/'),
));
$this->repository->expects($this->once())
->method('getPackages')
->will($this->returnValue(array()));
mkdir($this->vendorDir.'/.composer');
if (!is_dir($this->vendorDir.'/.composer')) {
mkdir($this->vendorDir.'/.composer');
}
$this->createClassFile($this->workingDir);
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
$this->assertAutoloadFiles('main', $this->vendorDir.'/.composer');
$this->assertAutoloadFiles('classmap', $this->vendorDir.'/.composer', 'classmap');
}
public function testVendorDirSameAsWorkingDir()
@ -88,7 +101,10 @@ class AutoloadGeneratorTest extends TestCase
$this->vendorDir = $this->workingDir;
$package = new MemoryPackage('a', '1.0', '1.0');
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
$package->setAutoload(array(
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
'classmap' => array('.composersrc/'),
));
$this->repository->expects($this->once())
->method('getPackages')
@ -98,14 +114,20 @@ class AutoloadGeneratorTest extends TestCase
mkdir($this->vendorDir.'/.composer', 0777, true);
}
$this->createClassFile($this->vendorDir);
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
$this->assertAutoloadFiles('main3', $this->vendorDir.'/.composer');
$this->assertAutoloadFiles('classmap3', $this->vendorDir.'/.composer', 'classmap');
}
public function testMainPackageAutoloadingAlternativeVendorDir()
{
$package = new MemoryPackage('a', '1.0', '1.0');
$package->setAutoload(array('psr-0' => array('Main' => 'src/', 'Lala' => 'src/')));
$package->setAutoload(array(
'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'),
'classmap' => array('.composersrc/'),
));
$this->repository->expects($this->once())
->method('getPackages')
@ -113,8 +135,10 @@ class AutoloadGeneratorTest extends TestCase
$this->vendorDir .= '/subdir';
mkdir($this->vendorDir.'/.composer', 0777, true);
$this->createClassFile($this->workingDir);
$this->generator->dump($this->repository, $package, $this->im, $this->vendorDir.'/.composer');
$this->assertAutoloadFiles('main2', $this->vendorDir.'/.composer');
$this->assertAutoloadFiles('classmap2', $this->vendorDir.'/.composer', 'classmap');
}
public function testVendorsAutoloading()
@ -169,6 +193,7 @@ class AutoloadGeneratorTest extends TestCase
),
include ($this->vendorDir.'/.composer/autoload_classmap.php')
);
$this->assertAutoloadFiles('classmap4', $this->vendorDir.'/.composer', 'classmap');
}
public function testOverrideVendorsAutoloading()
@ -191,8 +216,17 @@ class AutoloadGeneratorTest extends TestCase
$this->assertAutoloadFiles('override_vendors', $this->vendorDir.'/.composer');
}
private function assertAutoloadFiles($name, $dir)
private function createClassFile($basedir)
{
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_'.$name.'.php', $dir.'/autoload_namespaces.php');
if (!is_dir($basedir.'/.composersrc')) {
mkdir($basedir.'/.composersrc', 0777, true);
}
file_put_contents($basedir.'/.composersrc/foo.php', '<?php class ClassMapFoo {}');
}
private function assertAutoloadFiles($name, $dir, $type = 'namespaces')
{
$this->assertFileEquals(__DIR__.'/Fixtures/autoload_'.$name.'.php', $dir.'/autoload_'.$type.'.php');
}
}

View File

@ -0,0 +1,10 @@
<?php
// autoload_classmap.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'ClassMapFoo' => $baseDir . '/.composersrc/foo.php',
);

View File

@ -0,0 +1,10 @@
<?php
// autoload_classmap.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname(dirname($vendorDir));
return array(
'ClassMapFoo' => $baseDir . '/.composersrc/foo.php',
);

View File

@ -0,0 +1,10 @@
<?php
// autoload_classmap.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = $vendorDir;
return array(
'ClassMapFoo' => $baseDir . '/.composersrc/foo.php',
);

View File

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