Simple CLI test.
authorGunnar Wrobel <p@rdus.de>
Fri, 10 Dec 2010 05:17:44 +0000 (06:17 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 13 Dec 2010 10:17:24 +0000 (11:17 +0100)
framework/Kolab_Format/lib/Horde/Kolab/Format/Cli.php
framework/Kolab_Format/package.xml
framework/Kolab_Format/test/Horde/Kolab/Format/Unit/CliTest.php [new file with mode: 0644]

index e261481..7a38e45 100644 (file)
@@ -52,12 +52,9 @@ class Horde_Kolab_Format_Cli
         list($options, $arguments) = $parser->parseArgs();
         $factory = new Horde_Kolab_Format_Factory();
         $timed = $factory->createTimed('xml', 'task');
-        for ($i = 0; $i < 1000; $i++) {
-            $timed->load(
-                file_get_contents($arguments[0])
-            );
-        }
-        $cli->message($timed->timeSpent());
+        $content = file_get_contents($arguments[0]);
+        $timed->load($content);
+        $cli->message(floor($timed->timeSpent() * 1000) . ' ms');
     }
 
     static private function _prepareParser(array $parameters = array())
index fae382b..e3b41c7 100644 (file)
@@ -29,8 +29,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-12-09</date>
- <time>11:19:50</time>
+ <date>2010-12-10</date>
+ <time>06:10:51</time>
  <version>
   <release>1.1.0</release>
   <api>1.1.0</api>
@@ -88,6 +88,7 @@
         <file name="Note.php" role="php" />
         <file name="Task.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Format/Xml -->
+       <file name="Cli.php" role="php" />
        <file name="Date.php" role="php" />
        <file name="Exception.php" role="php" />
        <file name="Factory.php" role="php" />
         <dir name="Decorator">
          <file name="TimedTest.php" role="test" />
         </dir> <!-- /test/Horde/Kolab/Format/Unit/Decorator -->
+        <file name="CliTest.php" role="test" />
         <file name="FactoryTest.php" role="test" />
        </dir> <!-- /test/Horde/Kolab/Format/Unit -->
        <file name="AllTests.php" role="test" />
    <install as="Horde/Kolab/Format/event.php" name="examples/Horde/Kolab/Format/event.php" />
    <install as="Horde/Kolab/Format/new_type.php" name="examples/Horde/Kolab/Format/new_type.php" />
    <install as="Horde/Kolab/Format.php" name="lib/Horde/Kolab/Format.php" />
+   <install as="Horde/Kolab/Format/Cli.php" name="lib/Horde/Kolab/Format/Cli.php" />
    <install as="Horde/Kolab/Format/Date.php" name="lib/Horde/Kolab/Format/Date.php" />
    <install as="Horde/Kolab/Format/Exception.php" name="lib/Horde/Kolab/Format/Exception.php" />
    <install as="Horde/Kolab/Format/Factory.php" name="lib/Horde/Kolab/Format/Factory.php" />
    <install as="Horde/Kolab/Format/Integration/fixtures/preferences_write_old.xml" name="test/Horde/Kolab/Format/Integration/fixtures/preferences_write_old.xml" />
    <install as="Horde/Kolab/Format/Integration/fixtures/recur.xml" name="test/Horde/Kolab/Format/Integration/fixtures/recur.xml" />
    <install as="Horde/Kolab/Format/Integration/fixtures/recur_fail.xml" name="test/Horde/Kolab/Format/Integration/fixtures/recur_fail.xml" />
+   <install as="Horde/Kolab/Format/Unit/CliTest.php" name="test/Horde/Kolab/Format/Unit/CliTest.php" />
    <install as="Horde/Kolab/Format/Unit/FactoryTest.php" name="test/Horde/Kolab/Format/Unit/FactoryTest.php" />
    <install as="Horde/Kolab/Format/Unit/Decorator/TimedTest.php" name="test/Horde/Kolab/Format/Unit/Decorator/TimedTest.php" />
    <install as="COPYING" name="COPYING" />
     <release>stable</release>
     <api>stable</api>
    </stability>
-   <date>2010-12-09</date>
+   <date>2010-12-10</date>
    <license uri="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPL</license>
    <notes>
 * Removed dependency on the Kolab package within the task handler.
diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/CliTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/CliTest.php
new file mode 100644 (file)
index 0000000..e289255
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Test the CLI interface.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Format
+ * @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_Format
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../Autoload.php';
+
+/**
+ * Test the CLI interface.
+ *
+ * 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_Format
+ * @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_Format
+ */
+class Horde_Kolab_Format_Unit_CliTest
+extends PHPUnit_Framework_TestCase
+{
+    public function testCli()
+    {
+        $_SERVER['argv'] = array(
+            'kolab-format',
+            dirname(__FILE__) . '/../fixtures/task.xml'
+        );
+        ob_start();
+        Horde_Kolab_Format_Cli::main(
+            array(
+                'output' => new Horde_Test_Stub_Cli(),
+                'parser' => array('class' => 'Horde_Test_Stub_Parser')
+            )
+        );
+        $output = ob_get_contents();
+        ob_end_clean();
+        $this->assertRegExp(
+            '/INFO.*[0-9]+ ms/',
+            $output
+        );
+    }
+}