Supress errors for problematic backends.
authorGunnar Wrobel <p@rdus.de>
Tue, 21 Dec 2010 06:24:47 +0000 (07:24 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 4 Jan 2011 07:54:11 +0000 (08:54 +0100)
framework/Kolab_Cli/lib/Horde/Kolab/Cli.php
framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php [new file with mode: 0644]
framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Base.php
framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module/Folder.php
framework/Kolab_Cli/package.xml
framework/Kolab_Cli/test/Horde/Kolab/Cli/Unit/Cli/Module/BaseTest.php [new file with mode: 0644]

index c9c6473..0df5b8d 100644 (file)
@@ -55,6 +55,11 @@ class Horde_Kolab_Cli
             $parser->printHelp();
         } else {
             try {
+                foreach ($modular->getModules() as $module) {
+                    $modular->getProvider()
+                        ->getModule($module)
+                        ->handleArguments($options, $arguments);
+                }
                 if (!empty($options['timed'])
                     && class_exists('Horde_Support_Timer')) {
                     $timer = new Horde_Support_Timer();
diff --git a/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php b/framework/Kolab_Cli/lib/Horde/Kolab/Cli/Module.php
new file mode 100644 (file)
index 0000000..531762a
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * The Horde_Kolab_Cli_Module:: interface describes the module structure for
+ * Kolab_Cli.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Cli_Modular
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Cli_Modular
+ */
+
+/**
+ * The Horde_Kolab_Cli_Module:: interface describes the module structure for
+ * Kolab_Cli.
+ *
+ * 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  Cli_Modular
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Cli_Modular
+ */
+interface Horde_Kolab_Cli_Module
+extends Horde_Cli_Modular_Module
+{
+    /**
+     * Handle the options and arguments.
+     *
+     * @param mixed     $options   An array of options.
+     * @param mixed     $arguments An array of arguments.
+     *
+     * @return NULL
+     */
+    public function handleArguments($options, $arguments);
+}
\ No newline at end of file
index 8142999..702b710 100644 (file)
@@ -28,7 +28,7 @@
  * @link     http://pear.horde.org/index.php?package=Cli_Modular
  */
 class Horde_Kolab_Cli_Module_Base
-implements Horde_Cli_Modular_Module
+implements Horde_Kolab_Cli_Module
 {
     /**
      * Get the usage description for this module.
@@ -142,4 +142,23 @@ Choices are:
     {
         return array();
     }
+
+    /**
+     * Handle the options and arguments.
+     *
+     * @param mixed     $options   An array of options.
+     * @param mixed     $arguments An array of arguments.
+     *
+     * @return NULL
+     */
+    public function handleArguments($options, $arguments)
+    {
+        if (in_array($options['driver'], array('roundcube', 'php', 'pear'))) {
+            if (defined('E_DEPRECATED')) {
+                error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE);
+            } else {
+                error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);
+            }
+        }
+    }
 }
\ No newline at end of file
index ded4f61..d745160 100644 (file)
@@ -28,7 +28,7 @@
  * @link     http://pear.horde.org/index.php?package=Cli_Modular
  */
 class Horde_Kolab_Cli_Module_Folder
-implements Horde_Cli_Modular_Module
+implements Horde_Kolab_Cli_Module
 {
     /**
      * Get the usage description for this module.
@@ -94,6 +94,18 @@ implements Horde_Cli_Modular_Module
     }
 
     /**
+     * Handle the options and arguments.
+     *
+     * @param mixed     $options   An array of options.
+     * @param mixed     $arguments An array of arguments.
+     *
+     * @return NULL
+     */
+    public function handleArguments($options, $arguments)
+    {
+    }
+
+    /**
      * Run the module.
      *
      * @param Horde_Cli $cli       The CLI handler.
index 5dbd06d..1ff398e 100644 (file)
@@ -22,8 +22,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-12-16</date>
- <time>06:33:31</time>
+ <date>2010-12-21</date>
+ <time>07:16:30</time>
  <version>
   <release>0.0.1</release>
   <api>0.0.1</api>
@@ -49,6 +49,7 @@
         <file name="Base.php" role="php" />
         <file name="Folder.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Cli/Module -->
+       <file name="Module.php" role="php" />
        <file name="Translation.php" role="php" />
       </dir> <!-- /lib/Horde/Kolab/Cli -->
       <file name="Cli.php" role="php" />
@@ -61,6 +62,9 @@
       <dir name="Cli">
        <dir name="Unit">
         <dir name="Cli">
+         <dir name="Module">
+          <file name="BaseTest.php" role="test" />
+         </dir> <!-- /test/Horde/Kolab/Cli/Unit/Cli/Module -->
          <file name="ModuleTest.php" role="test" />
          <file name="OptionsTest.php" role="test" />
         </dir> <!-- /test/Horde/Kolab/Cli/Unit/Cli -->
   <filelist>
    <install as="klb" name="bin/klb" />
    <install as="Horde/Kolab/Cli.php" name="lib/Horde/Kolab/Cli.php" />
+   <install as="Horde/Kolab/Cli/Module.php" name="lib/Horde/Kolab/Cli/Module.php" />
    <install as="Horde/Kolab/Cli/Translation.php" name="lib/Horde/Kolab/Cli/Translation.php" />
    <install as="Horde/Kolab/Cli/Module/Base.php" name="lib/Horde/Kolab/Cli/Module/Base.php" />
    <install as="Horde/Kolab/Cli/Module/Folder.php" name="lib/Horde/Kolab/Cli/Module/Folder.php" />
    <install as="Horde/Kolab/Cli/Unit/CliTest.php" name="test/Horde/Kolab/Cli/Unit/CliTest.php" />
    <install as="Horde/Kolab/Cli/Unit/Cli/ModuleTest.php" name="test/Horde/Kolab/Cli/Unit/Cli/ModuleTest.php" />
    <install as="Horde/Kolab/Cli/Unit/Cli/OptionsTest.php" name="test/Horde/Kolab/Cli/Unit/Cli/OptionsTest.php" />
+   <install as="Horde/Kolab/Cli/Unit/Cli/Module/BaseTest.php" name="test/Horde/Kolab/Cli/Unit/Cli/Module/BaseTest.php" />
    <install as="COPYING" name="COPYING" />
   </filelist>
  </phprelease>
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-12-16</date>
+   <date>2010-12-21</date>
    <license uri="http://www.gnu.org/licenses/gpl.html">GPL</license>
    <notes>
 * Initial release.
diff --git a/framework/Kolab_Cli/test/Horde/Kolab/Cli/Unit/Cli/Module/BaseTest.php b/framework/Kolab_Cli/test/Horde/Kolab/Cli/Unit/Cli/Module/BaseTest.php
new file mode 100644 (file)
index 0000000..3d94a8c
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * Test the base modules.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Cli
+ * @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=Kolab_Cli
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../Autoload.php';
+
+/**
+ * Test the base modules.
+ *
+ * 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   Kolab
+ * @package    Kolab_Cli
+ * @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=Kolab_Cli
+ */
+class Horde_Kolab_Cli_Unit_Cli_Module_BaseTest
+extends Horde_Kolab_Cli_TestCase
+{
+    public function setUp()
+    {
+        $this->_storeErrorHandling();
+    }
+
+    public function tearDown()
+    {
+        $this->_restoreErrorHandling();
+    }
+
+    public function testNotice()
+    {
+        $this->assertTrue((bool) (error_reporting() & E_NOTICE));
+    }
+
+    public function testMissingNoticeWithRoundcubeDriver()
+    {
+        $base = new Horde_Kolab_Cli_Module_Base();
+        $base->handleArguments(array('driver' => 'roundcube'), array());
+        $this->assertFalse((bool) (error_reporting() & E_NOTICE));
+    }
+
+    public function testMissingNoticeWithHordeDriver()
+    {
+        $base = new Horde_Kolab_Cli_Module_Base();
+        $base->handleArguments(array('driver' => 'horde'), array());
+        $this->assertTrue((bool) (error_reporting() & E_NOTICE));
+    }
+
+    private function _storeErrorHandling()
+    {
+        $this->_error_handling = error_reporting();
+    }
+
+    private function _restoreErrorHandling()
+    {
+        error_reporting($this->_error_handling);
+    }
+}