/** * Check if DB test are possible * * @return void */ public static function setUpBeforeClass() { $current_datatbase = static::main_database(); // lets make sure that we have an db configuration for phpunit if (CCConfig::create('database')->has($current_datatbase)) { // lets try to connect to that database if the conection // fails we just return and continue the other tests try { DB::connect($current_datatbase); } catch (\PDOException $e) { return; } // connection succeeded? static::$dbtests = true; // overwrite the main db CCConfig::create('database')->set('main', $current_datatbase); // kill all connections Handler::kill_all_connections(); // check for any sql files that should be executed needed // for theses tests. We simply check if a file exists in the // CCUnit bundle "db_<current_database>.sql" if (file_exists(CCPath::get('CCUnit::db_' . $current_datatbase . '.sql'))) { $queries = explode(';', file_get_contents(CCPath::get('CCUnit::db_' . $current_datatbase . '.sql'))); foreach ($queries as $query) { $query = trim($query); if (!empty($query)) { DB::run($query, array(), 'phpunit'); } } } } }