/** * Tests that: * 1. an object can be registered with register(). * 2. attempting to register the same object throws an exception. * 3. the object is returned by registry('objectName'). * 4. the object is listed in the array returned by registry(). */ public function testRegistry() { /** * Register an object */ $obj = new stdClass(); // throws exception on failure Zend::register('objectName', $obj); /** * Attempt to register the same object again */ $e = null; try { Zend::register('another', $obj); } catch (Zend_Exception $e) { $this->assertRegExp('/duplicate(.*)objectName/i', $e->getMessage()); } if ($e === null) { $this->fail('No exception thown during registration of duplicate object.'); } /** * Attempt to retrieve the object with registry() */ $this->assertSame(Zend::registry('objectName'), $obj); /** * Check registry listing */ $this->assertEquals(Zend::registry(), array('objectName' => 'stdClass')); }
<?php require_once 'Zend/Controller/Front.php'; require_once 'Zend/View.php'; require_once dirname(__FILE__) . "/lib/plugins/UTF8Plugin.php"; require_once dirname(__FILE__) . "/lib/plugins/TestPlugin.php"; $front = Zend_Controller_Front::getInstance(); $front->setControllerDirectory('./app'); $front->registerPlugin(new UTF8Plugin()); $front->registerPlugin(new TestPlugin()); $view = new Zend_View(); $view->setScriptPath('./view'); Zend::register('view', $view); $front->dispatch();
public function testTableExceptionNoAdapter() { Zend::loadClass('Zend_Db_Table_ZfTestTable'); try { $dbTable = new Zend_Db_Table_ZfTestTable(array('db' => 327)); } catch (Exception $e) { $this->assertThat($e, $this->isInstanceOf('Zend_Db_Table_Exception'), 'Expecting object of type Zend_Db_Table_Exception'); $this->assertEquals($e->getMessage(), 'db object does not extend Zend_Db_Adapter_Abstract'); } Zend::register('registered_db', 327); try { $dbTable = new Zend_Db_Table_ZfTestTable(array('db' => 'registered_db')); } catch (Exception $e) { $this->assertThat($e, $this->isInstanceOf('Zend_Db_Table_Exception'), 'Expecting object of type Zend_Db_Table_Exception'); $this->assertEquals($e->getMessage(), 'db object does not extend Zend_Db_Adapter_Abstract'); } try { Zend_Db_Table_ZfTestTable::setDefaultAdapter(327); } catch (Exception $e) { $this->assertThat($e, $this->isInstanceOf('Zend_Db_Table_Exception'), 'Expecting object of type Zend_Db_Table_Exception'); $this->assertEquals($e->getMessage(), 'db object does not extend Zend_Db_Adapter_Abstract'); } }
<?php /** * Bootstrap file */ //error_reporting(E_ALL|E_STRICT); function __autoload($class) { Zend::loadClass($class); } set_include_path('../lib' . PATH_SEPARATOR . '../app/models'); include 'Zend.php'; $params = array('host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'uml'); $db = Zend_Db::factory('PDO_MYSQL', $params); Zend_Db_Table::setDefaultAdapter($db); Zend::register('db', $db); $controller = Zend_Controller_Front::getInstance(); $controller->setControllerDirectory('../app/controllers'); //$controller->registerPlugin(new Hamster_Controller_Plugin_First()); $user = Hamster_Auth::getInstance(); Zend::register('user', $user); $controller->dispatch();
/** * Tests that: * 1. an object can be registered with register(). * 2. the object is returned by registry('objectName'). * 3. the object is listed in the ArrayObject returned by registry(). * 4. isRegistered() returns correct states. */ public function testRegistry() { $registry = Zend::registry(); $this->assertFalse($registry->offsetExists('objectName')); $subregistry = new Zend_Registry(array('option1' => 'setting1', 'option2' => 'setting2')); // throws exception on failure Zend::register('componentOptions', $subregistry); $this->assertTrue($registry->offsetExists('componentOptions')); // compare fetched value with the expected value $this->assertSame(Zend::registry('componentOptions'), $subregistry); $this->assertTrue($registry->offsetGet('componentOptions') == new Zend_Registry(array('option1' => 'setting1', 'option2' => 'setting2'))); // Make sure a second object can be registered $object2 = new stdClass(); $this->assertNotSame($subregistry, $object2); // throws exception on failure $registry->offsetSet('componentOptions', $object2); $this->assertTrue($registry->offsetExists('componentOptions')); $this->assertNotSame(Zend::registry('componentOptions'), $subregistry); $this->assertSame(Zend::registry('componentOptions'), $object2); }