From 10b075af191f7eba245431faba2e5f24ed56583d Mon Sep 17 00:00:00 2001 From: Steve Buzonas Date: Tue, 8 Jan 2013 01:43:33 -0500 Subject: [PATCH] Added Common Installer, implemented new extra for webroot, created test cases for new package configuration. --- src/Composer/Installers/BaseInstaller.php | 6 ++++ src/Composer/Installers/CommonInstaller.php | 9 +++++ src/Composer/Installers/Installer.php | 3 +- .../Installers/Test/InstallerTest.php | 34 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/Composer/Installers/CommonInstaller.php diff --git a/src/Composer/Installers/BaseInstaller.php b/src/Composer/Installers/BaseInstaller.php index b6dbe362..d876a70f 100644 --- a/src/Composer/Installers/BaseInstaller.php +++ b/src/Composer/Installers/BaseInstaller.php @@ -42,6 +42,7 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '') } $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type')); + $availableVars['webroot'] = ''; $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { @@ -50,12 +51,17 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '') if ($this->composer->getPackage()) { $extra = $this->composer->getPackage()->getExtra(); + if (!empty($extra['installer-webroot'])) { + $availableVars['webroot'] = $extra['installer-webroot']; + } if (!empty($extra['installer-paths'])) { $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName); if ($customPath !== false) { return $this->templatePath($customPath, $availableVars); } } + } elseif ('common-webroot' === $type) { + throw new \InvalidArgumentException(sprintf('Package "%s" requires "installer-webroot" to be configured', $prettyName)); } $packageType = substr($type, strlen($frameworkType) + 1); diff --git a/src/Composer/Installers/CommonInstaller.php b/src/Composer/Installers/CommonInstaller.php new file mode 100644 index 00000000..6c1e23c5 --- /dev/null +++ b/src/Composer/Installers/CommonInstaller.php @@ -0,0 +1,9 @@ + '{$webroot}/', + ); +} diff --git a/src/Composer/Installers/Installer.php b/src/Composer/Installers/Installer.php index 04565b2f..017dcb8c 100644 --- a/src/Composer/Installers/Installer.php +++ b/src/Composer/Installers/Installer.php @@ -30,7 +30,8 @@ class Installer extends LibraryInstaller 'symfony1' => 'Symfony1Installer', 'wordpress' => 'WordPressInstaller', 'zend' => 'ZendInstaller', - 'typo3-flow' => 'TYPO3FlowInstaller' + 'typo3-flow' => 'TYPO3FlowInstaller', + 'common' => 'CommonInstaller' ); /** diff --git a/tests/Composer/Installers/Test/InstallerTest.php b/tests/Composer/Installers/Test/InstallerTest.php index 5faec52d..7b23bbbc 100644 --- a/tests/Composer/Installers/Test/InstallerTest.php +++ b/tests/Composer/Installers/Test/InstallerTest.php @@ -178,6 +178,40 @@ public function testGetCakePHPInstallPathException() $package->setType('cakephp-whoops'); $result = $installer->getInstallPath($package); } + + /** + * testCommonWebrootPackage + */ + public function testCommonWebrootPackage() + { + $installer = new Installer($this->io, $this->composer); + $package = new Package('slbmeh/my_application', '1.0.0', '1.0.0'); + + $package->setType('common-webroot'); + $consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0'); + $this->composer->setPackage($consumerPackage); + $consumerPackage->setExtra(array( + 'installer-webroot' => 'webroot' + )); + $result = $installer->getInstallPath($package); + $this->assertEquals('webroot/', $result); + } + + /** + * testCommonWebrootPackage + * + * @return void + * + * @expectedException \InvalidArgumentException + */ + public function testCommonWebrootPathException() + { + $installer = new Installer($this->io, $this->composer); + $package = new Package('slbmeh/my_application', '1.0.0', '1.0.0'); + + $package->setType('common-webroot'); + $result = $installer->getInstallPath($package); + } /** * testCustomInstallPath