Exemple #1
0
 public function tearDown()
 {
     \Zend\Db\Table\AbstractTable::setDefaultMetadataCache();
     // Restore original autoloaders
     $loaders = spl_autoload_functions();
     foreach ($loaders as $loader) {
         spl_autoload_unregister($loader);
     }
     foreach ($this->loaders as $loader) {
         spl_autoload_register($loader);
     }
     // Reset autoloader instance so it doesn't affect other tests
     Autoloader::resetInstance();
 }
Exemple #2
0
 /**
  * Set the default metadata cache
  * 
  * @param string|Zend_Cache_Core $cache
  * @return Zend_Application_Resource_Db
  */
 public function setDefaultMetadataCache($cache)
 {
     $metadataCache = null;
     if (is_string($cache)) {
         $bootstrap = $this->getBootstrap();
         if ($bootstrap instanceof \Zend\Application\ResourceBootstrapper && $bootstrap->hasPluginResource('CacheManager')) {
             $cacheManager = $bootstrap->bootstrap('CacheManager')->getResource('CacheManager');
             if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
                 $metadataCache = $cacheManager->getCache($cache);
             }
         }
     } else {
         if ($cache instanceof \Zend\Cache\Frontend) {
             $metadataCache = $cache;
         }
     }
     if ($metadataCache instanceof \Zend\Cache\Frontend) {
         \Zend\Db\Table\AbstractTable::setDefaultMetadataCache($metadataCache);
     }
     return $this;
 }
Exemple #3
0
 public function testTableSetDefaultMetadataCacheException()
 {
     try {
         Table\AbstractTable::setDefaultMetadataCache(new \stdClass());
         $this->fail('Expected to catch Zend_Db_Table_Exception');
     } catch (\Zend\Exception $e) {
         $this->assertType('Zend\\Db\\Table\\Exception', $e, 'Expecting object of type Zend_Db_Table_Exception, got ' . get_class($e));
         $this->assertEquals("Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored", $e->getMessage());
     }
     try {
         Table\AbstractTable::setDefaultMetadataCache(327);
         $this->fail('Expected to catch Zend_Db_Table_Exception');
     } catch (\Exception $e) {
         $this->assertType('Zend\\Db\\Table\\Exception', $e, 'Expecting object of type Zend_Db_Table_Exception, got ' . get_class($e));
         $this->assertEquals("Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored", $e->getMessage());
     }
 }
Exemple #4
0
 public function tearDown()
 {
     \Zend\Db\Table\AbstractTable::setDefaultMetadataCache();
 }