From 1322812420195993ece986d1744e2feb51cabdc1 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Thu, 9 Dec 2010 05:57:53 +0100 Subject: [PATCH] Add factory test. --- framework/Kolab_Format/lib/Horde/Kolab/Format.php | 21 +++++---- .../test/Horde/Kolab/Format/AllTests.php | 4 +- .../test/Horde/Kolab/Format/Autoload.php | 22 ++++----- .../test/Horde/Kolab/Format/Unit/FormatTest.php | 55 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 26 deletions(-) create mode 100644 framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FormatTest.php diff --git a/framework/Kolab_Format/lib/Horde/Kolab/Format.php b/framework/Kolab_Format/lib/Horde/Kolab/Format.php index fd52117ef..b53a055ed 100644 --- a/framework/Kolab_Format/lib/Horde/Kolab/Format.php +++ b/framework/Kolab_Format/lib/Horde/Kolab/Format.php @@ -8,7 +8,7 @@ * @package Kolab_Format * @author Gunnar Wrobel * @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 */ /** @@ -25,11 +25,10 @@ * @package Kolab_Format * @author Gunnar Wrobel * @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); - } diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php b/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php index 571fdafab..f8ba7d1c4 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/AllTests.php @@ -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. diff --git a/framework/Kolab_Format/test/Horde/Kolab/Format/Autoload.php b/framework/Kolab_Format/test/Horde/Kolab/Format/Autoload.php index 08ec31f5e..c376132b6 100644 --- a/framework/Kolab_Format/test/Horde/Kolab/Format/Autoload.php +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/Autoload.php @@ -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 * @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 index 000000000..f86c9c023 --- /dev/null +++ b/framework/Kolab_Format/test/Horde/Kolab/Format/Unit/FormatTest.php @@ -0,0 +1,55 @@ + + * @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 + * @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'); + } + + +} -- 2.11.0