Add an option to specify the target directory for a package snapshot. Add a test...
authorGunnar Wrobel <p@rdus.de>
Wed, 27 Oct 2010 19:44:23 +0000 (21:44 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 27 Oct 2010 19:44:23 +0000 (21:44 +0200)
components/lib/Components/Module/DevPackage.php
components/lib/Components/Pear/Package.php
components/lib/Components/Runner/DevPackage.php
components/lib/Components/Runner/Distribute.php
components/test/Components/Integration/Components/Module/DependenciesTest.php
components/test/Components/Integration/Components/Module/DevPackageTest.php [new file with mode: 0644]
components/test/Components/StoryTestCase.php

index e8cdaca..ec38229 100644 (file)
@@ -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.'
+                )
+            )
         );
     }
 
index e5e39c3..c2ec3b8 100644 (file)
@@ -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;
index 10fa861..fd29dcb 100644 (file)
@@ -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
         );
     }
 }
index ec6f5ad..881835c 100644 (file)
@@ -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();
index 3652d80..92855c0 100644 (file)
@@ -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 (file)
index 0000000..4b5587d
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Test the DevPackage module.
+ *
+ * PHP version 5
+ *
+ * @category   Horde
+ * @package    Components
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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
index f44fd9a..fde1239 100644 (file)
@@ -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(