Skip to content

Commit

Permalink
Added tests for the factory and singleton methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wood committed Jun 29, 2004
1 parent 672551b commit c3ce247
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 1 deletion.
74 changes: 74 additions & 0 deletions 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);
}
}
?>
4 changes: 3 additions & 1 deletion tests/runtests.php
Expand Up @@ -20,6 +20,8 @@
/**
* Auth_PrefManager2 test suite runner.
* @author Jon Wood <jon@jellybob.co.uk>
* @package Auth_PrefManager2
* @version 0.1.0
*/

/**
Expand All @@ -33,6 +35,6 @@
require_once('simpletest/reporter.php');

$test = &new GroupTest('All tests');

$test->addTestFile('CreationTests.php');
$test->run(new TextReporter());
?>
51 changes: 51 additions & 0 deletions 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);
}
}
?>

0 comments on commit c3ce247

Please sign in to comment.