Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
<?php

/**
 * CLI main application file.
 *
 * @package MerchantApp\Shell
 * @author  Ruslan Baydan <*****@*****.**>
 */
// Set application path.
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../app'));
// Composer autoload.
require realpath(APPLICATION_PATH . '/../vendor/autoload.php');
// Define application environment.
define('APPLICATION_ENV', getenv('APPLICATION_ENV') ?: 'live');
// Run the application.
\Library\MerchantApplication::run(APPLICATION_ENV, 'app.ini');
Exemplo n.º 4
0
#!/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);