From fde38dacec19754dafd0cec1f683dc886c55f5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Wed, 21 Mar 2012 13:58:35 +0100 Subject: [PATCH] Added test for generated classmap files --- .../Test/Autoload/AutoloadGeneratorTest.php | 46 ++++++++++++++++--- .../Autoload/Fixtures/autoload_classmap.php | 10 ++++ .../Autoload/Fixtures/autoload_classmap2.php | 10 ++++ .../Autoload/Fixtures/autoload_classmap3.php | 10 ++++ .../Autoload/Fixtures/autoload_classmap4.php | 12 +++++ 5 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 9d2d243a9..31be61d39 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -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', 'assertFileEquals(__DIR__.'/Fixtures/autoload_'.$name.'.php', $dir.'/autoload_'.$type.'.php'); } } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php new file mode 100644 index 000000000..8c1ab4190 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap.php @@ -0,0 +1,10 @@ + $baseDir . '/.composersrc/foo.php', +); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php new file mode 100644 index 000000000..2931e0f09 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap2.php @@ -0,0 +1,10 @@ + $baseDir . '/.composersrc/foo.php', +); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php new file mode 100644 index 000000000..15917ec1a --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php @@ -0,0 +1,10 @@ + $baseDir . '/.composersrc/foo.php', +); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php new file mode 100644 index 000000000..944a80bed --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php @@ -0,0 +1,12 @@ + $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', +);