Exemplo n.º 1
0
 /**
  * Gets an EntityManager for testing purposes.
  *
  * @param Configuration $config The Configuration to pass to the EntityManager.
  * @param EventManager $eventManager The EventManager to pass to the EntityManager.
  * @return EntityManager
  */
 protected function _getEntityManager($config = null, $eventManager = null)
 {
     // NOTE: Functional tests use their own shared metadata cache, because
     // the actual database platform used during execution has effect on some
     // metadata mapping behaviors (like the choice of the ID generation).
     if (is_null(self::$_metadataCacheImpl)) {
         self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache();
     }
     if (is_null(self::$_queryCacheImpl)) {
         self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache();
     }
     $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
     $this->_sqlLoggerStack->enabled = false;
     //FIXME: two different configs! $conn and the created entity manager have
     // different configs.
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(self::$_metadataCacheImpl);
     $config->setQueryCacheImpl(self::$_queryCacheImpl);
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Doctrine\\Tests\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
     $conn = static::$_sharedConn;
     $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
     // get rid of more global state
     $evm = $conn->getEventManager();
     foreach ($evm->getListeners() as $event => $listeners) {
         foreach ($listeners as $listener) {
             $evm->removeEventListener(array($event), $listener);
         }
     }
     if (isset($GLOBALS['db_event_subscribers'])) {
         foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) {
             $subscriberInstance = new $subscriberClass();
             $evm->addEventSubscriber($subscriberInstance);
         }
     }
     if (isset($GLOBALS['debug_uow_listener'])) {
         $evm->addEventListener(array('onFlush'), new \Doctrine\ORM\Tools\DebugUnitOfWorkListener());
     }
     return \Doctrine\ORM\EntityManager::create($conn, $config);
 }
 /**
  * Gets an EntityManager for testing purposes.
  *
  * @param Configuration $config The Configuration to pass to the EntityManager.
  * @param EventManager $eventManager The EventManager to pass to the EntityManager.
  * @return EntityManager
  */
 protected function _getEntityManager($config = null, $eventManager = null)
 {
     // NOTE: Functional tests use their own shared metadata cache, because
     // the actual database platform used during execution has effect on some
     // metadata mapping behaviors (like the choice of the ID generation).
     if (is_null(self::$_metadataCacheImpl)) {
         self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache();
     }
     if (is_null(self::$_queryCacheImpl)) {
         self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache();
     }
     $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
     $this->_sqlLoggerStack->enabled = false;
     //FIXME: two different configs! $conn and the created entity manager have
     // different configs.
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(self::$_metadataCacheImpl);
     $config->setQueryCacheImpl(self::$_queryCacheImpl);
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Doctrine\\Tests\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
     $conn = $this->sharedFixture['conn'];
     $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
     return \Doctrine\ORM\EntityManager::create($conn, $config);
 }
Exemplo n.º 3
0
 /**
  * Gets an EntityManager for testing purposes.
  *
  * @param Configuration $config The Configuration to pass to the EntityManager.
  * @param EventManager $eventManager The EventManager to pass to the EntityManager.
  * @return EntityManager
  */
 protected function _getEntityManager($config = null, $eventManager = null)
 {
     // NOTE: Functional tests use their own shared metadata cache, because
     // the actual database platform used during execution has effect on some
     // metadata mapping behaviors (like the choice of the ID generation).
     if (is_null(self::$_metadataCacheImpl)) {
         self::$_metadataCacheImpl = new \Doctrine\ORM\Cache\ArrayCache();
     }
     if (is_null(self::$_queryCacheImpl)) {
         self::$_queryCacheImpl = new \Doctrine\ORM\Cache\ArrayCache();
     }
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(self::$_metadataCacheImpl);
     $config->setQueryCacheImpl(self::$_queryCacheImpl);
     $eventManager = new \Doctrine\Common\EventManager();
     $conn = $this->sharedFixture['conn'];
     return \Doctrine\ORM\EntityManager::create($conn, $config, $eventManager);
 }
Exemplo n.º 4
0
 /**
  * Gets an EntityManager for testing purposes.
  *
  * @param \Doctrine\ORM\Configuration   $config       The Configuration to pass to the EntityManager.
  * @param \Doctrine\Common\EventManager $eventManager The EventManager to pass to the EntityManager.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 protected function _getEntityManager($config = null, $eventManager = null)
 {
     // NOTE: Functional tests use their own shared metadata cache, because
     // the actual database platform used during execution has effect on some
     // metadata mapping behaviors (like the choice of the ID generation).
     if (is_null(self::$_metadataCacheImpl)) {
         if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) {
             self::$_metadataCacheImpl = new $GLOBALS['DOCTRINE_CACHE_IMPL']();
         } else {
             self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache();
         }
     }
     if (is_null(self::$_queryCacheImpl)) {
         self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache();
     }
     $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack();
     $this->_sqlLoggerStack->enabled = false;
     //FIXME: two different configs! $conn and the created entity manager have
     // different configs.
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(self::$_metadataCacheImpl);
     $config->setQueryCacheImpl(self::$_queryCacheImpl);
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('Doctrine\\Tests\\Proxies');
     $enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE');
     if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) {
         $cacheConfig = new \Doctrine\ORM\Cache\CacheConfiguration();
         $cache = $this->getSharedSecondLevelCacheDriverImpl();
         $factory = new DefaultCacheFactory($cacheConfig->getRegionsConfiguration(), $cache);
         $this->secondLevelCacheFactory = $factory;
         if ($this->isSecondLevelCacheLogEnabled) {
             $this->secondLevelCacheLogger = new StatisticsCacheLogger();
             $cacheConfig->setCacheLogger($this->secondLevelCacheLogger);
         }
         $cacheConfig->setCacheFactory($factory);
         $config->setSecondLevelCacheEnabled(true);
         $config->setSecondLevelCacheConfiguration($cacheConfig);
         $this->isSecondLevelCacheEnabled = true;
     }
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Models/Cache'), realpath(__DIR__ . '/Models/GeoNames')), true));
     $conn = static::$_sharedConn;
     $conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack);
     // get rid of more global state
     $evm = $conn->getEventManager();
     foreach ($evm->getListeners() as $event => $listeners) {
         foreach ($listeners as $listener) {
             $evm->removeEventListener(array($event), $listener);
         }
     }
     if ($enableSecondLevelCache) {
         $evm->addEventListener('loadClassMetadata', new CacheMetadataListener());
     }
     if (isset($GLOBALS['db_event_subscribers'])) {
         foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) {
             $subscriberInstance = new $subscriberClass();
             $evm->addEventSubscriber($subscriberInstance);
         }
     }
     if (isset($GLOBALS['debug_uow_listener'])) {
         $evm->addEventListener(array('onFlush'), new \Doctrine\ORM\Tools\DebugUnitOfWorkListener());
     }
     return \Doctrine\ORM\EntityManager::create($conn, $config);
 }