From 02dc6ef0459cbc0a87cf341ca7de4435f40ad719 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Thu, 6 Oct 2011 12:11:04 +0400 Subject: [PATCH] Registry class tested --- tests/RegistryTest.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/RegistryTest.php diff --git a/tests/RegistryTest.php b/tests/RegistryTest.php new file mode 100644 index 0000000..4d82784 --- /dev/null +++ b/tests/RegistryTest.php @@ -0,0 +1,70 @@ + + * @link http://netmonsters.ru + * @package Majestic + * @subpackage UnitTests + * @since 2011-10-06 + * + * Unit tests for Registry + */ + +require_once '../Registry.php'; + +class RegistryTest extends PHPUnit_Framework_TestCase +{ + + private $_registry = null; + + public function setUp() + { + $this->_registry = Registry::getInstance(); + } + + public function testGetInstance() + { + $this->assertNotNull(Registry::getInstance()); + + $this->assertNotNull($this->_registry); + + $this->assertSame(Registry::getInstance(), $this->_registry); + } + + /** + * @TODO: make __construct private + */ +// public function testRegistryConstructor() +// { +// $this->setExpectedException('PHPUnit_Framework_Error'); +// $reg = new Registry(); +// } + + public function testSet() + { + Registry::set(1, 1); + Registry::set('two', 2); + $this->assertEquals(Registry::get(1), $this->_registry->get(1)); + $this->assertEquals(2, Registry::get('two')); + } + + public function testGet() + { + $this->assertEquals(Registry::get(1), $this->_registry->get(1)); + $this->assertEquals(Registry::get('two'), 2); + $this->assertNull(Registry::get(4)); + } + + /** + * @TODO: check input for null + * @expectedException PHPUnit_Framework_Error + */ + public function testIsRegistered() + { + $this->assertFalse(Registry::isRegistered(43)); + + $this->_registry->set(3, 'three'); + $this->assertTrue(Registry::isRegistered(3)); + $this->assertFalse(Registry::isRegistered(null)); + } +} \ No newline at end of file