public static function tearDownAfterClass() { // Remove the test DB. $config = MerchantApplication::app()->getConfig(); $dbFileName = APPLICATION_PATH . '/../' . $config->db->path . '/' . $config->db->name; if (file_exists($dbFileName)) { unlink($dbFileName); } }
/** * Returns the DB connection. * * @return mixed * * @throws \Exception */ public static function getConnection() { if (self::$_connection === null) { $config = MerchantApplication::app()->getConfig(); $adapter = !empty($config->db->adapter) ? $config->db->adapter : self::DEFAULT_ADAPTER; if (!extension_loaded($adapter)) { throw new \Exception('The ' . $adapter . ' extension is not loaded.'); } $dbClassName = '\\Library\\Model\\' . ucfirst($adapter); if (!class_exists($dbClassName)) { throw new \Exception('The DB connection class "' . $dbClassName . '" is not implemented.'); } self::$_connection = (new $dbClassName($config->db))->getConnection(); } return self::$_connection; }
#!/usr/bin/php <?php /** * This file is used to setup the SQLite database. * * @package MerchantApp\Shell * @author Ruslan Baydan <*****@*****.**> */ include 'shellApp.php'; use App\Models\Transaction; use Library\Model\Database; use Library\MerchantApplication; use App\Models\Merchant; use App\Models\CurrencyConverter; $config = MerchantApplication::app()->getConfig(); $db = Database::getConnection(); /* * Create the database tables. */ $schemaPath = APPLICATION_PATH . '/../data/' . $config->db->schema; if (!file_exists($schemaPath)) { throw new Exception('The schema file "' . $config->db->schema . '" does not exist.'); } $db->exec(file_get_contents($schemaPath)); /* * Parse data from CSV and insert into the database. */ if (!file_exists($config->testData->filepath)) { throw new Exception('Test data file "' . $config->testData->filepath . '" does not exist.'); } $testCsvData = array_slice(array_map('str_getcsv', file($config->testData->filepath)), 1);