Exemplo n.º 1
0
 /**
  * Basic setup of the mock database to perform tests against.
  *
  */
 public static function setUpBeforeClass()
 {
     self::$di = new \Anax\DI\CDIFactoryDefault();
     self::$app = new \Anax\MVC\CApplicationBasic(self::$di);
     self::$di->setShared('db', function () {
         $db = new \Mos\Database\CDatabaseBasic();
         $db->setOptions(['dsn' => "sqlite:memory::", "verbose" => false]);
         $db->connect();
         $db->dropTableIfExists('content')->execute();
         $db->createTable('content', ['id' => ['integer', 'primary key', 'not null', 'auto_increment'], 'slug' => ['varchar(80)', 'unique'], 'url' => ['varchar(80)', 'unique'], 'type' => ['varchar(80)'], 'title' => ['varchar(80)'], 'data' => ['text'], 'filter' => ['char(80)'], 'created' => ['datetime'], 'published' => ['datetime'], 'updated' => ['datetime'], 'deleted' => ['datetime'], 'owner' => ['varchar(80)'], 'updated_by' => ['varchar(80)']])->execute();
         $now = gmdate('Y-m-h H:i:s');
         $db->insert('content', ['slug', 'type', 'title', 'data', 'created', 'published', 'owner']);
         $db->execute(['a-first-article', 'article', 'A first article', 'This is the text of the first article.', $now, $now, 'admin']);
         return $db;
     });
 }
Exemplo n.º 2
0
$db = new \Mos\Database\CDatabaseBasic();
//
// Read config file
//
$options = (require "../config_mysql.php");
//
// Carry out som tests, db must exist
//
$db->setOptions($options);
$db->setTablePrefix($options['table_prefix']);
$db->connect();
//
// Drop a table if it exists
//
$tableName = 'test';
$db->dropTableIfExists($tableName)->execute();
//
// Create a table
//
$db->createTable($tableName, ['id' => ['integer', 'auto_increment', 'primary key', 'not null'], 'username' => ['varchar(20)'], 'password' => ['varchar(32)'], 'salt' => ['varchar(32)']])->execute();
//
// Add some users to test with
//
$sql = <<<EOD
INSERT INTO
    {$options['table_prefix']}{$tableName} (username, salt)
    VALUES (?, md5(NOW()));
EOD;
$db->execute($sql, ['doe']);
$db->execute($sql, ['admin']);
//