public function _before(\Codeception\TestCase $test) { // trying to connect to Symfony2 and get event manager if ($this->config['auto_connect']) { if ($this->hasModule('Symfony2')) { $symfonyModule = $this->getModule('Symfony2'); $kernel = $symfonyModule->kernel; if ($kernel->getContainer()->has('doctrine')) { self::$em = $kernel->getContainer()->get('doctrine.orm.entity_manager'); $symfonyModule->client->persistentServices[] = 'doctrine.orm.entity_manager'; $symfonyModule->client->persistentServices[] = 'doctrine.orm.default_entity_manager'; } } if ($this->hasModule('ZF2')) { $zf2Module = $this->getModule('ZF2'); $application = $zf2Module->application; $serviceLocator = $application->getServiceManager(); if ($entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager')) { self::$em = $entityManager; } } } if (!self::$em) { throw new \Codeception\Exception\ModuleConfig(__CLASS__, "Doctrine2 module requires EntityManager explicitly set.\n" . "You can use your bootstrap file to assign the EntityManager:\n\n" . '\\Codeception\\Module\\Doctrine2::$em = $em'); } if (!self::$em instanceof \Doctrine\ORM\EntityManager) { throw new \Codeception\Exception\ModuleConfig(__CLASS__, "Entity Manager was not properly set.\n" . "You can use your bootstrap file to assign the EntityManager:\n\n" . '\\Codeception\\Module\\Doctrine2::$em = $em'); } self::$em->getConnection()->connect(); if ($this->config['cleanup']) { self::$em->getConnection()->beginTransaction(); } }
public function _before(\Codeception\TestCase $test) { // trying to connect to Symfony2 to get event manager if (!self::$em && $this->config['auto_connect']) { if ($this->hasModule('Symfony2')) { $kernel = $this->getModule('Symfony2')->kernel; if ($kernel->getContainer()->has('doctrine')) { self::$em = $kernel->getContainer()->get('doctrine')->getEntityManager(); } } } if (!self::$em) { throw new \Codeception\Exception\ModuleConfig(__CLASS__, "Doctrine2 module requires EntityManager explictly set.\n" . "You can use your bootstrap file to assign the EntityManager:\n\n" . '\\Codeception\\Module\\Doctrine2::$em = $em'); } if (!self::$em instanceof \Doctrine\ORM\EntityManager) { throw new \Codeception\Exception\ModuleConfig(__CLASS__, "Entity Manager was not properly set.\n" . "You can use your bootstrap file to assign the EntityManager:\n\n" . '\\Codeception\\Module\\Doctrine2::$em = $em'); } self::$em->getConnection()->connect(); if ($this->config['cleanup']) { self::$em->getConnection()->beginTransaction(); } }