From 8989105beaf5feb7aa6732293c70f18552266b09 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Mon, 4 Oct 2010 17:18:25 +0200 Subject: [PATCH] Allow offline installs and testing. --- components/TODO | 2 - components/lib/Components/Pear/InstallLocation.php | 52 ++++++++++----- .../Components/Module/InstallerTest.php | 62 ++++++++++++++++++ .../test/Components/Integration/ComponentsTest.php | 23 ------- components/test/Components/StoryTestCase.php | 33 +++++++--- .../framework/Dependency/lib/Dependency.php | 1 + .../fixture/framework/Dependency/package.xml | 70 +++++++++++++++++++++ .../fixture/framework/Install/lib/Install.php | 1 + .../fixture/framework/Install/package.xml | 70 +++++++++++++++++++++ .../fixture/packages/Console_Getopt-1.9.1.tgz | Bin 0 -> 847 bytes .../Components/fixture/packages/PEAR-1.9.1.tgz | Bin 0 -> 832 bytes .../fixture/pear/Console_Getopt/lib/Console.php | 1 + .../fixture/pear/Console_Getopt/package.xml | 66 +++++++++++++++++++ .../test/Components/fixture/pear/PEAR/lib/PEAR.php | 1 + .../test/Components/fixture/pear/PEAR/package.xml | 66 +++++++++++++++++++ 15 files changed, 398 insertions(+), 50 deletions(-) create mode 100644 components/test/Components/Integration/Components/Module/InstallerTest.php create mode 100644 components/test/Components/fixture/framework/Dependency/lib/Dependency.php create mode 100644 components/test/Components/fixture/framework/Dependency/package.xml create mode 100644 components/test/Components/fixture/framework/Install/lib/Install.php create mode 100644 components/test/Components/fixture/framework/Install/package.xml create mode 100644 components/test/Components/fixture/packages/Console_Getopt-1.9.1.tgz create mode 100644 components/test/Components/fixture/packages/PEAR-1.9.1.tgz create mode 100644 components/test/Components/fixture/pear/Console_Getopt/lib/Console.php create mode 100644 components/test/Components/fixture/pear/Console_Getopt/package.xml create mode 100644 components/test/Components/fixture/pear/PEAR/lib/PEAR.php create mode 100644 components/test/Components/fixture/pear/PEAR/package.xml diff --git a/components/TODO b/components/TODO index ee354f67a..572263459 100644 --- a/components/TODO +++ b/components/TODO @@ -4,8 +4,6 @@ - Document usage - - Allow offline installs and testing - - Add module for an initial empty PEAR template - Fix variable replacements when updating the package.xml diff --git a/components/lib/Components/Pear/InstallLocation.php b/components/lib/Components/Pear/InstallLocation.php index 27d6c3e3c..7b7b85049 100644 --- a/components/lib/Components/Pear/InstallLocation.php +++ b/components/lib/Components/Pear/InstallLocation.php @@ -293,22 +293,32 @@ class Components_Pear_InstallLocation public function addPackageFromPackage($channel, $package) { $installer = $this->getInstallationHandler(); - $this->_output->warn( - sprintf( - 'Adding package %s via network.', - $package - ) - ); - ob_start(); - $installer->doInstall( - 'install', - array( - //'force' => true, - 'channel' => $channel, - ), - array($package) - ); - $this->_output->pear(ob_get_clean()); + if ($local = $this->_identifyMatchingLocalPackage($package)) { + ob_start(); + $installer->doInstall( + 'install', + array( + 'offline' => true + ), + array($local) + ); + $this->_output->pear(ob_get_clean()); + } else { + $this->_output->warn( + sprintf( + 'Adding package %s via network.', + $package + ) + ); + ob_start(); + $installer->doInstall( + 'install', + array( + 'channel' => $channel, + ), + array($package) + ); + } $this->_output->ok( sprintf( 'Successfully added package %s', @@ -316,4 +326,14 @@ class Components_Pear_InstallLocation ) ); } + + private function _identifyMatchingLocalPackage($package) + { + foreach (new DirectoryIterator($this->_source_directory) as $file) { + if (preg_match('/' . $package . '-[0-9]+(\.[0-9]+)+([a-z0-9]+)?/', $file->getBasename('.tgz'), $matches)) { + return $file->getPathname(); + } + } + return false; + } } diff --git a/components/test/Components/Integration/Components/Module/InstallerTest.php b/components/test/Components/Integration/Components/Module/InstallerTest.php new file mode 100644 index 000000000..12040d98e --- /dev/null +++ b/components/test/Components/Integration/Components/Module/InstallerTest.php @@ -0,0 +1,62 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../../Autoload.php'; + +/** + * Test the Installer module. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Components + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Integration_Components_Module_InstallerTest +extends Components_StoryTestCase +{ + /** + * @scenario + */ + public function theInstallerModuleAddsTheIOptionInTheHelpOutput() + { + $this->given('the default Components setup') + ->when('calling the package with the help option') + ->then('the help will contain the "i" option.'); + } + + /** + * @scenario + */ + public function theTheIOptionInstallsThePackageFromTheCurrentTree() + { + $this->given('the default Components setup') + ->when('calling the package with the install option and a path to a Horde framework component') + ->then('a new PEAR configuration file will be installed') + ->and('the dummy PEAR package will be installed') + ->and('the non-Horde dependencies of the component will get installed') + ->and('the Horde dependencies of the component will get installed from the current tree') + ->and('the component will be installed') + ->and('the installation requires no network access.'); + } +} \ No newline at end of file diff --git a/components/test/Components/Integration/ComponentsTest.php b/components/test/Components/Integration/ComponentsTest.php index 0068dc29c..d6e662d79 100644 --- a/components/test/Components/Integration/ComponentsTest.php +++ b/components/test/Components/Integration/ComponentsTest.php @@ -131,27 +131,4 @@ extends Components_StoryTestCase * understand. */ - /** - * @scenario - */ - public function theInstallerModuleAddsTheIOptionInTheHelpOutput() - { - $this->given('the default Components setup') - ->when('calling the package with the help option') - ->then('the help will contain the "i" option.'); - } - - /** - * @scenario - */ - public function theTheIOptionInstallsThePackageFromTheCurrentTree() - { - $this->given('the default Components setup') - ->when('calling the package with the install option and a Horde element') - ->then('a new PEAR configuration file will be installed') - ->and('the PEAR package will be installed') - ->and('the non-Horde dependencies of the Horde element will get installed from the network.') - ->and('the Horde dependencies of the Horde element will get installed from the current tree.') - ->and('the Components library will be installed'); - } } \ No newline at end of file diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php index 97045b605..6d8484052 100644 --- a/components/test/Components/StoryTestCase.php +++ b/components/test/Components/StoryTestCase.php @@ -142,12 +142,13 @@ extends PHPUnit_Extensions_Story_TestCase ); $world['output'] = $this->_callUnstrictComponents(); break; - case 'calling the package with the install option and a Horde element': + case 'calling the package with the install option and a path to a Horde framework component': $_SERVER['argv'] = array( 'horde-components', '--channelxmlpath=' . dirname(__FILE__) . '/fixture/channels', + '--sourcepath=' . dirname(__FILE__) . '/fixture/packages', '--install=' . $this->_getTemporaryDirectory(), - dirname(__FILE__) . '/../../' + dirname(__FILE__) . '/fixture/framework/Install' ); $world['output'] = $this->_callUnstrictComponents(); break; @@ -215,7 +216,7 @@ extends PHPUnit_Extensions_Story_TestCase file_exists($this->_temp_dir . DIRECTORY_SEPARATOR . '.pearrc') ); break; - case 'the PEAR package will be installed': + case 'the dummy PEAR package will be installed': $this->assertTrue( file_exists( $this->_temp_dir . DIRECTORY_SEPARATOR @@ -225,25 +226,23 @@ extends PHPUnit_Extensions_Story_TestCase ) ); break; - case 'the non-Horde dependencies of the Horde element will get installed from the network.': + case 'the non-Horde dependencies of the component will get installed': $this->assertTrue( file_exists( $this->_temp_dir . DIRECTORY_SEPARATOR . 'pear' . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR - . 'PEAR' . DIRECTORY_SEPARATOR - . 'PackageFileManager2.php' + . 'Console.php' ) ); break; - case 'the Horde dependencies of the Horde element will get installed from the current tree.': + case 'the Horde dependencies of the component will get installed from the current tree': $this->assertTrue( file_exists( $this->_temp_dir . DIRECTORY_SEPARATOR . 'pear' . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR - . 'Horde' . DIRECTORY_SEPARATOR - . 'Autoloader.php' + . 'Dependency.php' ) ); break; @@ -257,6 +256,16 @@ extends PHPUnit_Extensions_Story_TestCase ) ); break; + case 'the component will be installed': + $this->assertTrue( + file_exists( + $this->_temp_dir . DIRECTORY_SEPARATOR + . 'pear' . DIRECTORY_SEPARATOR + . 'php' . DIRECTORY_SEPARATOR + . 'Install.php' + ) + ); + break; case 'the CI configuration will be installed.': $this->assertTrue( file_exists( @@ -265,6 +274,12 @@ extends PHPUnit_Extensions_Story_TestCase ) ); break; + case 'the installation requires no network access.': + $this->assertNotContains( + 'network', + $world['output'] + ); + break; case 'the CI build script will be installed.': $this->assertTrue( file_exists( diff --git a/components/test/Components/fixture/framework/Dependency/lib/Dependency.php b/components/test/Components/fixture/framework/Dependency/lib/Dependency.php new file mode 100644 index 000000000..a81436628 --- /dev/null +++ b/components/test/Components/fixture/framework/Dependency/lib/Dependency.php @@ -0,0 +1 @@ + + + Dependency + pear.php.net + Test fixture. + A dummy package.xml used for testing the Components package. + + Gunnar Wrobel + wrobel + p@rdus.de + yes + + 2010-08-22 + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + LGPL + +* Initial release + + + + + + + + + + + + 5.0.0 + + + 1.7.0 + + + Console_Getopt + pear.php.net + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-08-22 + LGPL + +* Initial release + + + + diff --git a/components/test/Components/fixture/framework/Install/lib/Install.php b/components/test/Components/fixture/framework/Install/lib/Install.php new file mode 100644 index 000000000..a81436628 --- /dev/null +++ b/components/test/Components/fixture/framework/Install/lib/Install.php @@ -0,0 +1 @@ + + + Install + pear.php.net + Test fixture. + A dummy package.xml used for testing the Components package. + + Gunnar Wrobel + wrobel + p@rdus.de + yes + + 2010-08-22 + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + LGPL + +* Initial release + + + + + + + + + + + + 5.0.0 + + + 1.7.0 + + + Dependency + pear.horde.org + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-08-22 + LGPL + +* Initial release + + + + diff --git a/components/test/Components/fixture/packages/Console_Getopt-1.9.1.tgz b/components/test/Components/fixture/packages/Console_Getopt-1.9.1.tgz new file mode 100644 index 0000000000000000000000000000000000000000..a6441fc9df80ef3d0a2cb42e0353ea70449f0168 GIT binary patch literal 847 zcmV-V1F-xbiwFP!000021MF5&kJ~m3zUTWDgdYdQvVBQ<7bxzEVml1D0Y%$keJd1; zNrcL>XDQ9yzaOQ@iJf(AA9e#aga}}Xq&`aIM@6luK8X#ckF~yfF3GcOKApl9K>lKu z4ZlHdrt|q>6deKP1*xts^8CVIQsv<@c2+fJndE7f0Gg_i%50X&Z|{Ge+$Jx}Yu+As z0`c1oR^0hD$9dsrglX(D**e!Q7;8~2mGPhVLP%#-}&|7g|G zd%xeO`(%5T(N>*meGyl(2YF=(9a{RnjkMaUY3 zq;EXJ{mvNC!S7wOLVY{|aDwm3ebk1D*HUQ|9qY$V?rbWNvxCB$MCH_HET7PF7RMBf z#b{g#hh>rF*@S-Cly>D6WN?Zi=Cj4@ZjtAlg(;~cR|9m1gks5yXiP5sG(>Gxul7S9 z@wAc?u~tee_cVg>T8)3j>GeI(a5dMeLSrfI-I&uGvkRn-cFP(qC&!82w3=v>r(0L+ zq~+gxg?)y4j3a z7=jI0J}^;2&UhXf8Vv`6!iei|#`Xc6(Ct=y2`(B=aASl)&t|uiqB!;}JX1Ts*BSx_ zEdj&R94^+FVBTNW<@NvP|9|{9GYR({J0s#VzyC;PPt=j2ZS009600{{_N6V(6`007dyqX+;1 literal 0 HcmV?d00001 diff --git a/components/test/Components/fixture/packages/PEAR-1.9.1.tgz b/components/test/Components/fixture/packages/PEAR-1.9.1.tgz new file mode 100644 index 0000000000000000000000000000000000000000..22b7ecaa0cd9761b1b0b61c96110243f461972db GIT binary patch literal 832 zcmV-G1Hb$qiwFP!000021MF69Z`&Xc?&toBlRr+1vC}whBjRqFwrNr)O?%Pyl^Bws zVeA1}+JC=;;Ka$Qwjb6?n{tX|xR>V+?t##<>IYkh^rluPPbGPljYlIm0m#pbtp5#i zHX5C6M$r*qJRIk6a+IeRdWD^bU&2_~=xLItSpq^=4VQW`O}>74JGe-$%2V2IcmnZj zdJ&gCW;-AH8DeTXO_t8J6GB?SOxiBnR0~JA<0OI%cD@tG?2mgQf_aed{BNw>dau{( zbbXdKWeLsV5urnOLIKc13Kiw<^G*Ua3OUxalqmp5)@L`q4gMh`A*Wn}A@ zUcLg3hFkDSx|YJq3J&wefI|#yKe(lU*G=6vT4-lGKSb?AA+i#T<2M%mZlyId@Xa(c zp|&dkitwgfM{SsREjC2rvR)d#vMCpoY!u$aDkp!5@>W<%;uw>Wn2mDgL^;gzY=FOP zgjIP38l1$8c`+%9NtRI(rl^h#4bVm)ibXFZZ%#=!4Ov^+sr}Gr+(lBP(@ZMqZuelk zR*64xI(-M!kETjiLR;K+v(My(UIi*gyCsd{gY85uT7_iE)1|9bQeMCNcuhOkz?}xW zSDwCr_gXs16vUc*`e;KoHQM=>hC;bCFhh@UR+Pf&G$9H2zWIUo0XmmT+~rmC0x334 z=7P;cQB~v1e3o5Y@G;}!Ok^WIp5?=AUUhg%&WIG+)QKa}F&{dYbrM#uNx^SuB5cDIjml%pKwDF1@|1^@v6{{sNQ KrP$s85&!^>F^`A< literal 0 HcmV?d00001 diff --git a/components/test/Components/fixture/pear/Console_Getopt/lib/Console.php b/components/test/Components/fixture/pear/Console_Getopt/lib/Console.php new file mode 100644 index 000000000..a81436628 --- /dev/null +++ b/components/test/Components/fixture/pear/Console_Getopt/lib/Console.php @@ -0,0 +1 @@ + + + Console_Getopt + pear.php.net + Test fixture. + A dummy PEAR package used for testing the Components package. + + Gunnar Wrobel + wrobel + p@rdus.de + yes + + 2010-10-04 + + + 1.9.1 + 1.9.1 + + + stable + stable + + LGPL + +* Initial release + + + + + + + + + + + + 5.0.0 + + + 1.7.0 + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-08-22 + LGPL + +* Initial release + + + + diff --git a/components/test/Components/fixture/pear/PEAR/lib/PEAR.php b/components/test/Components/fixture/pear/PEAR/lib/PEAR.php new file mode 100644 index 000000000..a81436628 --- /dev/null +++ b/components/test/Components/fixture/pear/PEAR/lib/PEAR.php @@ -0,0 +1 @@ + + + PEAR + pear.php.net + Test fixture. + A dummy PEAR package used for testing the Components package. + + Gunnar Wrobel + wrobel + p@rdus.de + yes + + 2010-10-04 + + + 1.9.1 + 1.9.1 + + + stable + stable + + LGPL + +* Initial release + + + + + + + + + + + + 5.0.0 + + + 1.7.0 + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-08-22 + LGPL + +* Initial release + + + + -- 2.11.0