From 32c4dac082310c4e5041a0540cf1b348f7447f22 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 27 Oct 2010 21:44:23 +0200 Subject: [PATCH] Add an option to specify the target directory for a package snapshot. Add a test for the DevPackage runner. Add some more code coverage. --- components/lib/Components/Module/DevPackage.php | 8 +++ components/lib/Components/Pear/Package.php | 8 ++- components/lib/Components/Runner/DevPackage.php | 11 ++++- components/lib/Components/Runner/Distribute.php | 2 +- .../Components/Module/DependenciesTest.php | 11 +++++ .../Components/Module/DevPackageTest.php | 57 ++++++++++++++++++++++ components/test/Components/StoryTestCase.php | 28 +++++++++++ 7 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 components/test/Components/Integration/Components/Module/DevPackageTest.php diff --git a/components/lib/Components/Module/DevPackage.php b/components/lib/Components/Module/DevPackage.php index e8cdacaa8..ec38229e1 100644 --- a/components/lib/Components/Module/DevPackage.php +++ b/components/lib/Components/Module/DevPackage.php @@ -51,6 +51,14 @@ extends Components_Module_Base 'help' => 'generate a development snapshot' ) ), + new Horde_Argv_Option( + '-Z', + '--archivedir', + array( + 'action' => 'store', + 'help' => 'the path to the directory where any resulting source archives will be placed.' + ) + ) ); } diff --git a/components/lib/Components/Pear/Package.php b/components/lib/Components/Pear/Package.php index e5e39c333..c2ec3b8f6 100644 --- a/components/lib/Components/Pear/Package.php +++ b/components/lib/Components/Pear/Package.php @@ -457,21 +457,25 @@ class Components_Pear_Package /** * Generate a snapshot of the package using the provided version number. * - * @param string $varsion The snapshot version. + * @param string $version The snapshot version. + * @param string $archive_dir The path where the snapshot should be placed. * * @return string The path to the snapshot. */ - public function generateSnapshot($version) + public function generateSnapshot($version, $archive_dir) { $pkg = $this->_getPackageFile(); $pkg->_packageInfo['version']['release'] = $version; $pkg->setDate(date('Y-m-d')); $pkg->setTime(date('H:i:s')); ob_start(); + $old_dir = getcwd(); + chdir($archive_dir); $result = Components_Exception_Pear::catchError( $pkg->getDefaultGenerator() ->toTgz(new PEAR_Common()) ); + chdir($old_dir); $this->_output->pear(ob_get_clean()); $this->_output->ok('Generated snapshot ' . $result); return $result; diff --git a/components/lib/Components/Runner/DevPackage.php b/components/lib/Components/Runner/DevPackage.php index 10fa8617d..fd29dcb57 100644 --- a/components/lib/Components/Runner/DevPackage.php +++ b/components/lib/Components/Runner/DevPackage.php @@ -69,14 +69,21 @@ class Components_Runner_DevPackage public function run() { - $options = $this->_config->getOptions(); $arguments = $this->_config->getArguments(); $package = $this->_factory->createPackageForDefaultLocation( $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml' ); + + $options = $this->_config->getOptions(); + if ($options['archivedir']) { + $archivedir = $options['archivedir']; + } else { + $archivedir = getcwd(); + } $package->generateSnapshot( - $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M') + $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M'), + $archivedir ); } } diff --git a/components/lib/Components/Runner/Distribute.php b/components/lib/Components/Runner/Distribute.php index ec6f5ad61..881835c9c 100644 --- a/components/lib/Components/Runner/Distribute.php +++ b/components/lib/Components/Runner/Distribute.php @@ -102,7 +102,7 @@ class Components_Runner_Distribute $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml' ); $version = $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M'); - $package->generateSnapshot($version); + $package->generateSnapshot($version, dirname($options['distribute'])); ob_start(); include $template->getPathname(); diff --git a/components/test/Components/Integration/Components/Module/DependenciesTest.php b/components/test/Components/Integration/Components/Module/DependenciesTest.php index 3652d80fb..92855c00b 100644 --- a/components/test/Components/Integration/Components/Module/DependenciesTest.php +++ b/components/test/Components/Integration/Components/Module/DependenciesTest.php @@ -59,6 +59,17 @@ extends Components_StoryTestCase /** * @scenario */ + public function theTheLOptionListThePackageDependenciesAsTreeWithoutColorIfSelected() + { + $this->given('the default Components setup') + ->when('calling the package with the list dependencies option, the nocolor option and a path to a Horde framework component') + ->then('the non-Horde dependencies of the component will be listed') + ->and('the Horde dependencies of the component will be listed'); + } + + /** + * @scenario + */ public function theTheVerboseLOptionListThePackageDependenciesAsTree() { $this->given('the default Components setup') diff --git a/components/test/Components/Integration/Components/Module/DevPackageTest.php b/components/test/Components/Integration/Components/Module/DevPackageTest.php new file mode 100644 index 000000000..4b5587d35 --- /dev/null +++ b/components/test/Components/Integration/Components/Module/DevPackageTest.php @@ -0,0 +1,57 @@ + + * @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 DevPackage 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_DevPackageTest +extends Components_StoryTestCase +{ + /** + * @scenario + */ + public function theDevPackageModuleAddsTheDOptionInTheHelpOutput() + { + $this->given('the default Components setup') + ->when('calling the package with the help option') + ->then('the help will contain the option', '-d,\s*--devpackage'); + } + + /** + * @scenario + */ + public function theTheLowerCaseDOptionGeneratesAPackageSnapshot() + { + $this->given('the default Components setup') + ->when('calling the package with the devpackage option, the archive directory option and a path to a Horde framework component') + ->then('a package snapshot will be generated at the indicated archive directory'); + } +} \ No newline at end of file diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php index f44fd9ae1..fde12395e 100644 --- a/components/test/Components/StoryTestCase.php +++ b/components/test/Components/StoryTestCase.php @@ -213,6 +213,15 @@ extends PHPUnit_Extensions_Story_TestCase ); $world['output'] = $this->_callUnstrictComponents(); break; + case 'calling the package with the list dependencies option, the nocolor option and a path to a Horde framework component': + $_SERVER['argv'] = array( + 'horde-components', + '--nocolor', + '--list-deps', + dirname(__FILE__) . '/fixture/framework/Install' + ); + $world['output'] = $this->_callUnstrictComponents(); + break; case 'calling the package with the quiet list dependencies option and a path to a Horde framework component': $_SERVER['argv'] = array( 'horde-components', @@ -222,6 +231,16 @@ extends PHPUnit_Extensions_Story_TestCase ); $world['output'] = $this->_callUnstrictComponents(); break; + case 'calling the package with the devpackage option, the archive directory option and a path to a Horde framework component': + $_SERVER['argv'] = array( + 'horde-components', + '--verbose', + '--devpackage', + '--archivedir=' . $this->_getTemporaryDirectory(), + dirname(__FILE__) . '/fixture/framework/Install' + ); + $world['output'] = $this->_callUnstrictComponents(); + break; case 'calling the package with the distribute option and a path to a Horde framework component': $_SERVER['argv'] = array( 'horde-components', @@ -433,6 +452,15 @@ extends PHPUnit_Extensions_Story_TestCase $world['output'] ); break; + case 'a package snapshot will be generated at the indicated archive directory': + $found = false; + foreach (new DirectoryIterator($this->_temp_dir) as $file) { + if (preg_match('/Install-[0-9]+(\.[0-9]+)+([a-z0-9]+)?/', $file->getBasename('.tgz'), $matches)) { + $found = true; + } + } + $this->assertTrue($found); + break; case 'a package definition will be generated at the indicated location': $this->assertTrue( file_exists( -- 2.11.0