From: Gunnar Wrobel Date: Mon, 4 Oct 2010 15:18:25 +0000 (+0200) Subject: Allow offline installs and testing. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8989105beaf5feb7aa6732293c70f18552266b09;p=horde.git Allow offline installs and testing. --- 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 000000000..a6441fc9d Binary files /dev/null and b/components/test/Components/fixture/packages/Console_Getopt-1.9.1.tgz differ 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 000000000..22b7ecaa0 Binary files /dev/null and b/components/test/Components/fixture/packages/PEAR-1.9.1.tgz differ 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 + + + +