Eccube\Tests\EccubeTestCase::createApplication PHP Method

createApplication() public method

public createApplication ( )
    public function createApplication()
    {
        $app = Application::getInstance();
        $app['debug'] = true;
        // ログの内容をERRORレベルでしか出力しないように設定を上書き
        $app['config'] = $app->share($app->extend('config', function ($config, \Silex\Application $app) {
            $config['log']['log_level'] = 'ERROR';
            $config['log']['action_level'] = 'ERROR';
            $config['log']['passthru_level'] = 'ERROR';
            $channel = $config['log']['channel'];
            foreach (array('monolog', 'front', 'admin') as $key) {
                $channel[$key]['log_level'] = 'ERROR';
                $channel[$key]['action_level'] = 'ERROR';
                $channel[$key]['passthru_level'] = 'ERROR';
            }
            $config['log']['channel'] = $channel;
            return $config;
        }));
        $app->initLogger();
        $app->initialize();
        $app->initializePlugin();
        $app['session.test'] = true;
        $app['exception_handler']->disable();
        $app['form.csrf_provider'] = $app->share(function () {
            return new CsrfTokenMock();
        });
        $app->register(new \Eccube\Tests\ServiceProvider\FixtureServiceProvider());
        $app->boot();
        return $app;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @see http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/
  */
 public function getConnection()
 {
     // 別途 Application を生成しているような箇所があると動作しないので注意
     $app = EccubeTestCase::createApplication();
     // Get an instance of your entity manager
     $entityManager = $app['orm.em'];
     // Retrieve PDO instance
     $pdo = $entityManager->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $entityManager->clear();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $config = new Configuration($app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     $migration->migrate(null, false);
     self::$app = $app;
     // Pass to PHPUnit
     return $this->createDefaultDBConnection($pdo, 'db_name');
 }
All Usage Examples Of Eccube\Tests\EccubeTestCase::createApplication