From c3ce24741e54666dd470c77a230e0e4226fdbea2 Mon Sep 17 00:00:00 2001 From: Jon Wood Date: Tue, 29 Jun 2004 16:56:07 +0000 Subject: [PATCH] Added tests for the factory and singleton methods. git-svn-id: http://svn.php.net/repository/pear/packages/Auth_PrefManager2/trunk@162309 c90b9560-bf6c-de11-be94-00142212c4b1 --- tests/CreationTests.php | 74 +++++++++++++++++++++++++++++++++ tests/runtests.php | 4 +- tests/support/MockContainer.php | 51 +++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/CreationTests.php create mode 100644 tests/support/MockContainer.php diff --git a/tests/CreationTests.php b/tests/CreationTests.php new file mode 100644 index 0000000..fcb7fa0 --- /dev/null +++ b/tests/CreationTests.php @@ -0,0 +1,74 @@ + | +// | Paul M. Jones | +// +----------------------------------------------------------------------+ +// +// $Id$ + +/** + * Require Auth_PrefManager2 for testing. + */ +require_once('Auth/PrefManager2.php'); +require_once('support/MockContainer.php'); + +/** + * Test cases to ensure that the factory and singleton methods work. + * + * @author Jon Wood + * @package Auth_PrefManager2 + * @version 0.1.0 + */ +class CreationTests extends UnitTestCase +{ + /** + * Constructor + * + * @access public + * @return void + */ + function CreationTests() + { + $this->UnitTestCase(); + } + + /** + * Test the factory method. + * + * @access public + * @return void + * @todo Switch to using a full container once one is done. + */ + function testFactory() + { + $object =& Auth_PrefManager2::factory("Mock"); + $this->assertIsA($object, "Auth_PrefManager2_Mock"); + } + + /** + * Test the factory method. + * + * @access public + * @return void + * @todo Switch to using a full container once one is done. + */ + function testSingleton() + { + $object =& Auth_PrefManager2::singleton("Mock"); + $reference =& Auth_PrefManager2::singleton("Mock"); + + $this->assertReference($object, $reference); + } +} +?> diff --git a/tests/runtests.php b/tests/runtests.php index 94d22ec..e2a154f 100644 --- a/tests/runtests.php +++ b/tests/runtests.php @@ -20,6 +20,8 @@ /** * Auth_PrefManager2 test suite runner. * @author Jon Wood + * @package Auth_PrefManager2 + * @version 0.1.0 */ /** @@ -33,6 +35,6 @@ require_once('simpletest/reporter.php'); $test = &new GroupTest('All tests'); - +$test->addTestFile('CreationTests.php'); $test->run(new TextReporter()); ?> diff --git a/tests/support/MockContainer.php b/tests/support/MockContainer.php new file mode 100644 index 0000000..541b8d9 --- /dev/null +++ b/tests/support/MockContainer.php @@ -0,0 +1,51 @@ + | +// | Paul M. Jones | +// +----------------------------------------------------------------------+ +// +// $Id$ + +/** + * Require the base class. + */ +require_once('Auth/PrefManager2.php'); + +/** + * A mock container for testing the factory and singleton methods. + * + * @author Jon Wood + * @package Auth_PrefManager2 + * @category Authentication + * @version 0.1.0 + */ +class Auth_PrefManager2_Mock extends Auth_PrefManager2 +{ + /** + * Constructor + * + * Applications should never call this constructor directly, instead + * create a container with the factory method. + * + * @access protected + * @param array $options An associative array of options. + * @return void + * @see Auth_PrefManager2::&factory() + */ + function Auth_PrefManager2_Mock($options = array()) + { + $this->Auth_PrefManager2($options); + } +} +?>