コード例 #1
0
 public function testInstance()
 {
     //echo __LINE__, "\n";
     // Make sure we get a Zend_Registry object
     #$registry1 = Zend::initRegistry();
     Zend::register('foo', 'bar');
     $this->assertTrue(Zend::isRegistered('foo'));
     $registry1 = Zend::registry();
     $this->assertEquals(get_class($registry1), 'Zend_Registry');
     // should receive a reference to the same object
     $registry2 = Zend::registry();
     $this->assertSame($registry1, $registry2);
     // compare existing registry with a duplicate
     $registry4 = new Zend_Registry(array('foo' => 'bar'));
     $this->assertTrue($registry2 == $registry4);
     // make sure these are not the same, since one is empty, and the other is not
     $this->assertNotSame($registry1, new Zend_Registry());
 }
コード例 #2
0
ファイル: ZendTest.php プロジェクト: jorgenils/zend-framework
 /**
  * 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().
  *   5. isRegistered() returns correct states.
  */
 public function testRegistry()
 {
     $this->assertFalse(Zend::isRegistered('objectName'));
     /**
      * Register an object
      */
     $obj = new stdClass();
     // throws exception on failure
     Zend::register('objectName', $obj);
     $this->assertTrue(Zend::isRegistered('objectName'));
     /**
      * 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'));
 }