protected function getConnection() { if (is_null($this->app)) { $this->app = $this->getApplication(); } $this->em = EntityManagerFactory::initializeTestEntityManager($this->app); $pdo = $this->em->getConnection()->getWrappedConnection(); $this->em->clear(); $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $classes = $this->em->getMetadataFactory()->getAllMetadata(); $tool->dropSchema($classes); $tool->createSchema($classes); return $this->createDefaultDBConnection($pdo, 'fcms_test'); }
static function initializeTestEntityManager($app, $applicationMode = "development") { $cache = new \Doctrine\Common\Cache\ArrayCache(); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl($cache); //Load this paths from config file $driverImpl = $config->newDefaultAnnotationDriver(EntityManagerFactory::prepareEntityFoldersPaths($app)); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setProxyDir(rtrim($app['rootFolderPath']) . DIRECTORY_SEPARATOR . "temp" . DIRECTORY_SEPARATOR); $config->setProxyNamespace('FCMS2\\DoctrineProxy'); $config->setAutoGenerateProxyClasses(true); $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => 'true'), $config); return $em; }
//Register Configuration Files Service //Loads repository of configuration parameters from specified files $app->register(new \Yosymfony\Silex\ConfigServiceProvider\ConfigServiceProvider(array($app['rootFolderPath'] . "/config/"))); $app['config'] = $app->share(function () use($app) { return $app['configuration']->load('config.json'); }); // Setting application execution mode $app['debug'] = $app['config']->get('Application.Debug'); if ($app['config']->get('Application.Development')) { $applicationMode = "development"; } else { $applicationMode = "production"; } // Initializing Entity Manager Doctrine ORM $app['em'] = $app->share(function () use($app, $applicationMode) { return \Core\EntityManagerFactory::initializeEntityManager($app, $app['config']->get('Database'), $applicationMode); }); $monologConf = $app['config']->get('Log'); //Register Monolog Logging Service $app->register(new \Core\RotatingHandlerMonologServiceProvider(), array('monolog.logfile' => $app['rootFolderPath'] . '/log/' . $monologConf['filename'], 'monolog.maxfiles' => $monologConf['maxfiles'], 'monolog.level' => $monologConf['level'], 'monolog.name' => $monologConf['name'])); $app['monolog'] = $app->share($app->extend('monolog', function ($monolog, $app) { /** * @var Monolog\Logger $monolog */ $monolog->pushProcessor(new \Monolog\Processor\IntrospectionProcessor(\Monolog\Logger::ERROR)); return $monolog; })); //Register Controller Service //Dynamically loads controllers for app->match $app->register(new \Silex\Provider\ServiceControllerServiceProvider()); //Register Url Generator Service