Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests for the factory and singleton methods.

  • Loading branch information...
commit c3ce24741e54666dd470c77a230e0e4226fdbea2 1 parent 672551b
Jon Wood authored
View
74 tests/CreationTests.php
@@ -0,0 +1,74 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2004 Jon Wood |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Jon Wood <jon@jellybob.co.uk> |
+// | Paul M. Jones <pmjones@ciaweb.net> |
+// +----------------------------------------------------------------------+
+//
+// $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 <jon@jellybob.co.uk>
+ * @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);
+ }
+}
+?>
View
4 tests/runtests.php
@@ -20,6 +20,8 @@
/**
* Auth_PrefManager2 test suite runner.
* @author Jon Wood <jon@jellybob.co.uk>
+ * @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());
?>
View
51 tests/support/MockContainer.php
@@ -0,0 +1,51 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | Copyright (c) 2004 Jon Wood |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.txt. |
+// | If you did not receive a copy of the PHP license and are unable to |
+// | obtain it through the world-wide-web, please send a note to |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Jon Wood <jon@jellybob.co.uk> |
+// | Paul M. Jones <pmjones@ciaweb.net> |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+/**
+ * Require the base class.
+ */
+require_once('Auth/PrefManager2.php');
+
+/**
+ * A mock container for testing the factory and singleton methods.
+ *
+ * @author Jon Wood <jon@jellybob.co.uk>
+ * @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);
+ }
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.