Пример #1
0
 public function test_query()
 {
     $limit = 5;
     $rows = Generic::query("SELECT * FROM `scoop`.`test` LIMIT ?", [$limit]);
     $this->assertEquals($limit, $rows->get_num_rows());
     $dbConfig = \Scoop\Config::get_db_config();
     $dbConfig['database'] = 'scoop';
     $connection = new \Scoop\Database\Connection($dbConfig);
     $rows = Generic::query("SELECT * FROM test LIMIT ?", [$limit], $connection);
     $this->assertEquals($limit, $rows->get_num_rows());
 }
Пример #2
0
 public function test_get_db_config()
 {
     // base db config
     $expected = (require __DIR__ . "/../configs/db.php");
     $this->assertEquals($expected, Config::get_db_config());
     // site db config
     if (Config::option_exists('server_document_root')) {
         $docRoot = Config::get_option('server_document_root');
     }
     // set up a fake site document root
     Config::set_option('server_document_root', getcwd() . '/' . time());
     // get the expected config file path
     $siteDbConfigPath = Config::get_site_db_config_path();
     // create the expected config file path
     if (mkdir(Config::get_site_class_path(), 0777, true) && mkdir(dirname($siteDbConfigPath), 0777, true)) {
         // the site db config values
         $siteDbConfig = ['host' => 'new.host', 'user' => 'new.user'];
         // create the php code for the site config file
         $contents = '<?php return ' . var_export($siteDbConfig, true) . ';';
         // write the config to file
         $bytesWritten = file_put_contents($siteDbConfigPath, $contents, true);
         if ($bytesWritten !== false) {
             // reload global db config in hopes site values have overridden global ones
             $dbConfig = Config::get_db_config();
             // check that site db config values are there
             foreach ($siteDbConfig as $key => $value) {
                 $this->assertEquals($value, $dbConfig[$key], "options in site db config should override the global db config");
             }
             // check values not in site db config are still loaded from global config
             foreach ($expected as $key => $value) {
                 if (!array_key_exists($key, $siteDbConfig)) {
                     $this->assertEquals($value, $dbConfig[$key], "options not in site db config should be loaded from the global config");
                 }
             }
         }
     }
     // delete our tmp site doc root
     \Scoop\File::delete_directory(Config::get_option('server_document_root'));
     // set config values back to what they were
     if (isset($docRoot)) {
         Config::set_option('server_document_root', $docRoot);
     } else {
         Config::unset_option('server_document_root');
     }
 }
Пример #3
0
 public function __construct()
 {
     $this->cache = new Statement(500);
     $dbConfig = \Scoop\Config::get_db_config();
     $this->cache->put(0, new mysqli_stmt(new mysqli($dbConfig['host'], $dbConfig['user'], $dbConfig['password'], '', $dbConfig['port']), ''));
 }
Пример #4
0
 public static function connect()
 {
     if (is_null(self::$connection)) {
         self::$connection = new Connection(Config::get_db_config());
     }
 }
Пример #5
0
 public function test___destruct()
 {
     $connection = new Connection(\Scoop\Config::get_db_config());
     unset($connection);
 }