Add factory test.
authorGunnar Wrobel <p@rdus.de>
Thu, 9 Dec 2010 04:57:53 +0000 (05:57 +0100)
committerGunnar Wrobel <p@rdus.de>
Mon, 13 Dec 2010 10:17:01 +0000 (11:17 +0100)
framework/Kolab_Format/lib/Horde/Kolab/Format.php
framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php
framework/Kolab_Format/test/Horde/Kolab/Format/Autoload.php
framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FormatTest.php [new file with mode: 0644]

index fd52117..b53a055 100644 (file)
@@ -8,7 +8,7 @@
  * @package  Kolab_Format
  * @author   Gunnar Wrobel <wrobel@pardus.de>
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ * @link     http://pear.horde.org/index.php?package=Kolab_Format
  */
 
 /**
  * @package  Kolab_Format
  * @author   Gunnar Wrobel <wrobel@pardus.de>
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Server
+ * @link     http://pear.horde.org/index.php?package=Kolab_Format
  */
 abstract class Horde_Kolab_Format
 {
-
     /**
      * Attempts to return a concrete Horde_Kolab_Format instance based on
      * $format_type.
@@ -46,16 +45,19 @@ abstract class Horde_Kolab_Format
      *
      * @throws Horde_Kolab_Format_Exception If the specified driver could not be loaded.
      */
-    static public function &factory($format_type = '', $object_type = '',
-                                    $params = null)
+    static public function factory($format_type = '', $object_type = '',
+                                   $params = null)
     {
         $class = 'Horde_Kolab_Format_' . ucfirst(strtolower($format_type));
         if (class_exists($class)) {
-            $driver = call_user_func(array($class, 'factory'), $object_type,
-                                     $params);
+            $driver = call_user_func(
+                array($class, 'factory'), $object_type, $params
+            );
         } else {
-            throw new Horde_Kolab_Format_Exception(sprintf('Failed to load Kolab Format driver %s',
-                                              $format_type));
+            throw new Horde_Kolab_Format_Exception(
+                sprintf('Failed to load Kolab Format driver %s',
+                        $format_type)
+            );
         }
 
         return $driver;
@@ -103,5 +105,4 @@ abstract class Horde_Kolab_Format
      * @throws Horde_Kolab_Format_Exception
      */
     abstract public function save($object);
-
 }
index 571fdaf..f8ba7d1 100644 (file)
@@ -22,12 +22,12 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 /**
  * Prepare the test setup.
  */
-require_once dirname(__FILE__) . '/Autoload.php';
+require_once 'Horde/Test/AllTests.php';
 
 /**
  * Combine the tests for this package.
  *
- * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
+ * Copyright 2007-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.
index 08ec31f..c376132 100644 (file)
@@ -4,26 +4,20 @@
  *
  * PHP version 5
  *
+ * Copyright 2009-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
+ * @package    Kolab_Config
  * @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
+ * @link       http://pear.horde.org/index.php?package=Kolab_Config
  */
 
-if (!spl_autoload_functions()) {
-    spl_autoload_register(
-        create_function(
-            '$class',
-            '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);
-             $err_mask = E_ALL ^ E_WARNING;
-             $oldErrorReporting = error_reporting($err_mask);
-             include "$filename.php";
-             error_reporting($oldErrorReporting);'
-        )
-    );
-}
+require_once 'Horde/Test/Autoload.php';
 
 /** Catch strict standards */
 error_reporting(E_ALL | E_STRICT);
diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FormatTest.php b/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FormatTest.php
new file mode 100644 (file)
index 0000000..f86c9c0
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Test the format entry point.
+ *
+ * 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 format entry point.
+ *
+ * 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_FormatTest
+extends PHPUnit_Framework_TestCase
+{
+    public function testFactory()
+    {
+        $this->assertInstanceOf(
+            'Horde_Kolab_Format_Xml_Contact',
+            Horde_Kolab_Format::factory('XML', 'contact')
+        );
+    }
+
+    /**
+     * @expectedException Horde_Kolab_Format_Exception
+     */
+    public function testFactoryException()
+    {
+        Horde_Kolab_Format::factory('UNKNOWN', 'contact');
+    }
+
+
+}