Allow offline installs and testing.
authorGunnar Wrobel <p@rdus.de>
Mon, 4 Oct 2010 15:18:25 +0000 (17:18 +0200)
committerGunnar Wrobel <p@rdus.de>
Mon, 4 Oct 2010 15:19:50 +0000 (17:19 +0200)
15 files changed:
components/TODO
components/lib/Components/Pear/InstallLocation.php
components/test/Components/Integration/Components/Module/InstallerTest.php [new file with mode: 0644]
components/test/Components/Integration/ComponentsTest.php
components/test/Components/StoryTestCase.php
components/test/Components/fixture/framework/Dependency/lib/Dependency.php [new file with mode: 0644]
components/test/Components/fixture/framework/Dependency/package.xml [new file with mode: 0644]
components/test/Components/fixture/framework/Install/lib/Install.php [new file with mode: 0644]
components/test/Components/fixture/framework/Install/package.xml [new file with mode: 0644]
components/test/Components/fixture/packages/Console_Getopt-1.9.1.tgz [new file with mode: 0644]
components/test/Components/fixture/packages/PEAR-1.9.1.tgz [new file with mode: 0644]
components/test/Components/fixture/pear/Console_Getopt/lib/Console.php [new file with mode: 0644]
components/test/Components/fixture/pear/Console_Getopt/package.xml [new file with mode: 0644]
components/test/Components/fixture/pear/PEAR/lib/PEAR.php [new file with mode: 0644]
components/test/Components/fixture/pear/PEAR/package.xml [new file with mode: 0644]

index ee354f6..5722634 100644 (file)
@@ -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
index 27d6c3e..7b7b850 100644 (file)
@@ -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 (file)
index 0000000..12040d9
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Test the Installer 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 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 <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_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
index 0068dc2..d6e662d 100644 (file)
@@ -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
index 97045b6..6d84840 100644 (file)
@@ -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 (file)
index 0000000..a814366
--- /dev/null
@@ -0,0 +1 @@
+<?php
\ No newline at end of file
diff --git a/components/test/Components/fixture/framework/Dependency/package.xml b/components/test/Components/fixture/framework/Dependency/package.xml
new file mode 100644 (file)
index 0000000..59c2f77
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Dependency</name>
+ <channel>pear.php.net</channel>
+ <summary>Test fixture.</summary>
+ <description>A dummy package.xml used for testing the Components package.</description>
+ <lead>
+  <name>Gunnar Wrobel</name>
+  <user>wrobel</user>
+  <email>p@rdus.de</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-08-22</date>
+ <time>21:12:03</time>
+ <version>
+  <release>0.0.1</release>
+  <api>0.0.1</api>
+ </version>
+ <stability>
+  <release>alpha</release>
+  <api>alpha</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+ <notes>
+* Initial release
+ </notes>
+ <contents>
+  <dir baseinstalldir="/" name="/">
+   <dir name="lib">
+    <file name="Dependency.php" role="php" />
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.0.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.7.0</min>
+   </pearinstaller>
+   <package>
+    <name>Console_Getopt</name>
+    <channel>pear.php.net</channel>
+   </package>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install as="Dependency.php" name="lib/Dependency.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2010-08-22</date>
+   <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+   <notes>
+* Initial release
+   </notes>
+  </release>
+ </changelog>
+</package>
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 (file)
index 0000000..a814366
--- /dev/null
@@ -0,0 +1 @@
+<?php
\ No newline at end of file
diff --git a/components/test/Components/fixture/framework/Install/package.xml b/components/test/Components/fixture/framework/Install/package.xml
new file mode 100644 (file)
index 0000000..b26ce1d
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Install</name>
+ <channel>pear.php.net</channel>
+ <summary>Test fixture.</summary>
+ <description>A dummy package.xml used for testing the Components package.</description>
+ <lead>
+  <name>Gunnar Wrobel</name>
+  <user>wrobel</user>
+  <email>p@rdus.de</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-08-22</date>
+ <time>21:12:03</time>
+ <version>
+  <release>0.0.1</release>
+  <api>0.0.1</api>
+ </version>
+ <stability>
+  <release>alpha</release>
+  <api>alpha</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+ <notes>
+* Initial release
+ </notes>
+ <contents>
+  <dir baseinstalldir="/" name="/">
+   <dir name="lib">
+    <file name="Install.php" role="php" />
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.0.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.7.0</min>
+   </pearinstaller>
+   <package>
+    <name>Dependency</name>
+    <channel>pear.horde.org</channel>
+   </package>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install as="Install.php" name="lib/Install.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2010-08-22</date>
+   <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+   <notes>
+* Initial release
+   </notes>
+  </release>
+ </changelog>
+</package>
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 (file)
index 0000000..a6441fc
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 (file)
index 0000000..22b7eca
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 (file)
index 0000000..a814366
--- /dev/null
@@ -0,0 +1 @@
+<?php
\ No newline at end of file
diff --git a/components/test/Components/fixture/pear/Console_Getopt/package.xml b/components/test/Components/fixture/pear/Console_Getopt/package.xml
new file mode 100644 (file)
index 0000000..c1e1713
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Console_Getopt</name>
+ <channel>pear.php.net</channel>
+ <summary>Test fixture.</summary>
+ <description>A dummy PEAR package used for testing the Components package.</description>
+ <lead>
+  <name>Gunnar Wrobel</name>
+  <user>wrobel</user>
+  <email>p@rdus.de</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-10-04</date>
+ <time>21:12:03</time>
+ <version>
+  <release>1.9.1</release>
+  <api>1.9.1</api>
+ </version>
+ <stability>
+  <release>stable</release>
+  <api>stable</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+ <notes>
+* Initial release
+ </notes>
+ <contents>
+  <dir baseinstalldir="/" name="/">
+   <dir name="lib">
+    <file name="Console.php" role="php" />
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.0.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.7.0</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install as="Console.php" name="lib/Console.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2010-08-22</date>
+   <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+   <notes>
+* Initial release
+   </notes>
+  </release>
+ </changelog>
+</package>
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 (file)
index 0000000..a814366
--- /dev/null
@@ -0,0 +1 @@
+<?php
\ No newline at end of file
diff --git a/components/test/Components/fixture/pear/PEAR/package.xml b/components/test/Components/fixture/pear/PEAR/package.xml
new file mode 100644 (file)
index 0000000..ccd70a5
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>PEAR</name>
+ <channel>pear.php.net</channel>
+ <summary>Test fixture.</summary>
+ <description>A dummy PEAR package used for testing the Components package.</description>
+ <lead>
+  <name>Gunnar Wrobel</name>
+  <user>wrobel</user>
+  <email>p@rdus.de</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-10-04</date>
+ <time>21:12:03</time>
+ <version>
+  <release>1.9.1</release>
+  <api>1.9.1</api>
+ </version>
+ <stability>
+  <release>stable</release>
+  <api>stable</api>
+ </stability>
+ <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+ <notes>
+* Initial release
+ </notes>
+ <contents>
+  <dir baseinstalldir="/" name="/">
+   <dir name="lib">
+    <file name="PEAR.php" role="php" />
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.0.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.7.0</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install as="PEAR.php" name="lib/PEAR.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2010-08-22</date>
+   <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
+   <notes>
+* Initial release
+   </notes>
+  </release>
+ </changelog>
+</package>