Add a test for creating the package.xml from scratch and fix some notices.
authorGunnar Wrobel <p@rdus.de>
Wed, 27 Oct 2010 18:45:52 +0000 (20:45 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 27 Oct 2010 18:45:52 +0000 (20:45 +0200)
components/lib/Components/Pear/Factory.php
components/lib/Components/Pear/Package.php
components/test/Components/Integration/Components/Module/PearPackageXmlTest.php
components/test/Components/StoryTestCase.php

index 36cbcca..ffcbebd 100644 (file)
@@ -206,11 +206,12 @@ class Components_Pear_Factory
         );
         $pkg->setLicense('REPLACE', 'REPLACE');
         $pkg->setNotes('* Initial release.');
-        $pkg->clearContents();
+        $pkg->clearContents(true);
         $pkg->clearDeps();
         $pkg->setPhpDep('5.2.0');
         $pkg->setPearinstallerDep('1.9.0');
         $pkg->setPackageType('php');
+        $pkg->addFile('', 'something', array('role' => 'php'));
         new PEAR_Validate();
         return Components_Exception_Pear::catchError(
             $pkg->getDefaultGenerator()
index 0eb12c7..e5e39c3 100644 (file)
@@ -256,6 +256,9 @@ class Components_Pear_Package
         $updated = $package->getContents();
         $updated = $updated['dir']['file'];
         foreach ($updated as $file) {
+            if (!isset($file['attribs'])) {
+                continue;
+            }
             if (isset($taskfiles[$file['attribs']['name']])) {
                 foreach ($taskfiles[$file['attribs']['name']] as $tag => $raw) {
                     $taskname = $package->getTask($tag) . '_rw';
@@ -316,6 +319,9 @@ class Components_Pear_Package
         $horde_role = false;
 
         foreach ($files as $file) {
+            if (!isset($file['attribs'])) {
+                continue;
+            }
             $components = explode('/', $file['attribs']['name'], 2);
             switch ($components[0]) {
             case 'doc':
index e579062..d69bbb7 100644 (file)
@@ -69,6 +69,16 @@ extends Components_StoryTestCase
     /**
      * @scenario
      */
+    public function theUOptionWillCreateANewPackageXmlInCaseItIsMissing()
+    {
+        $this->given('the default Components setup')
+            ->when('calling the package with the updatexml option and a path without package.xml')
+            ->then('a new package.xml will be created.');
+    }
+
+    /**
+     * @scenario
+     */
     public function thePOptionFailsWithoutAValidDirectoryPath()
     {
         $this->given('the default Components setup')
index 1d0c509..f44fd9a 100644 (file)
@@ -84,6 +84,20 @@ extends PHPUnit_Extensions_Story_TestCase
             );
             $world['output'] = $this->_callUnstrictComponents();
             break;
+        case 'calling the package with the updatexml option and a path without package.xml':
+            $temp = $this->_getTemporaryDirectory();
+            mkdir($temp . DIRECTORY_SEPARATOR . 'test');
+            file_put_contents(
+                $temp . DIRECTORY_SEPARATOR . 'test'  . DIRECTORY_SEPARATOR . 'test.php',
+                '<?php'
+            );
+            $_SERVER['argv'] = array(
+                'horde-components',
+                '--updatexml',
+                $temp
+            );
+            $world['output'] = $this->_callUnstrictComponents();
+            break;
         case 'calling the package with the pearrc, the packagexml option, and a Horde component':
             $_SERVER['argv'] = array(
                 'horde-components',
@@ -301,6 +315,11 @@ extends PHPUnit_Extensions_Story_TestCase
                 $world['output']
             );
             break;
+        case 'a new package.xml will be created.':
+            $this->assertTrue(
+                file_exists($this->_temp_dir . DIRECTORY_SEPARATOR . 'package.xml')
+            );
+            break;
         case 'a new PEAR configuration file will be installed':
             $this->assertTrue(
                 file_exists($this->_temp_dir . DIRECTORY_SEPARATOR . '.pearrc')