Пример #1
0
 /**
  * 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');
                 }
             }
         }
     }
 }
 /**
  * Executes a SQL query and returns the primary key of the affected row
  *
  * @param string $query SQL query
  * @return bool Returns true if all is well otherwise returns false
  * @throws \DomainException Throws an exception if the query is not valid
  */
 public function queryUpdate(string $query) : bool
 {
     $db = DB::getGlobal();
     $result = $db->query($query, $this->statementValues);
     if ($result == false) {
         throw new \DomainException(sprintf('%s $query SQL syntax error: %s', __METHOD__, $query));
     }
     $this->statementValues = array();
     return $result;
 }
 /**
  * Starts the framework
  *
  * @param string|null $settings Path to settings file
  * @return int If all is well then it returns zero
  * @throws \Exception
  */
 public static function run(string $settings = null) : int
 {
     $settingsFile = $settings ? $settings : realpath(dirname(__FILE__) . '/../../../' . 'settings.yml');
     # load settings
     if (!Settings::load($settingsFile)) {
         return false;
     }
     if (Settings::getProduction()) {
         ini_set('display_errors', 'Off');
         ini_set('error_log', '/tmp/php-error.log');
         ini_set('log_errors', 1);
     }
     # set timezone
     Timezone::setTimezone(Settings::getTimezone());
     # set locale language
     I18n::setLocale(I18n::getLanguage());
     # generate routes
     if (Settings::getAutoroute()) {
         Routing::generateRoutes();
     }
     # load routes
     $routesFile = Settings::getRoutesFile();
     if (file_exists($routesFile)) {
         self::$routes = YAML::load($routesFile);
     } else {
         printf('[Error] Routes file %s does not exists', $routesFile);
         return false;
     }
     $dbSettings = Settings::getDBSettings();
     $db = new DB($dbSettings['dbm'], $dbSettings['host'], $dbSettings['name'], $dbSettings['user'], $dbSettings['password']);
     DB::setGlobal($db);
     # load actions
     Actions::autoloader(Settings::getActionsPath());
     Session::start();
     $request = isset($_GET[Settings::SETTINGS_ROUTE_PARAM_VALUE]) ? $_GET[Settings::SETTINGS_ROUTE_PARAM_VALUE] : '';
     if (Routing::parseRoute($request, self::$routes) == -1) {
         Response::response(Response::HTTP_FORBIDDEN);
     }
     return 0;
 }