예제 #1
0
 private static function init_test_tables()
 {
     $adapter = new \common\adapters\MysqlAdapter('');
     $sql = '
         CREATE TABLE IF NOT EXISTS tests_table (
           `id` serial primary key
           , `field1` varchar(255) not null default ""
           , `field2` bigint not null default 0
           , `field3` enum("val1", "val2", "val3") default "val1"
         )
     ';
     $adapter->execute($sql);
     $sql = '
         CREATE TABLE IF NOT EXISTS tests_table2 (
           `id` serial primary key
           , `field1` varchar(255) not null default ""
           , `field2` bigint not null default 0
           , `field3` enum("val1", "val2", "val3") default "val1"
         )
     ';
     $adapter->execute($sql);
     $roles = [User::credentials_admin, User::credentials_admin, User::credentials_admin, User::credentials_user, User::credentials_user, User::credentials_user, User::credentials_super_admin, User::credentials_super_admin, User::credentials_super_admin];
     /**
      * @var $user User
      */
     $user = Application::get_class(User::class);
     $mapper = $user->get_mapper();
     for ($i = 0; $i < 9; $i++) {
         $mapper->save(new \User\models\UserModel(['login' => uniqid('test', true), 'credentials' => $roles[$i]]));
     }
 }
예제 #2
0
 private function init_db()
 {
     if (defined('TESTS_ENV') || Application::is_dev()) {
         $adapter = new \common\adapters\MysqlAdapter('');
         $sql = 'SHOW TABLES';
         $tables = ['users', 'session', 'templates'];
         if (count(array_intersect($adapter->execute($sql)->get_arrays(), $tables)) < count($tables)) {
             $sql = file_get_contents(ROOT_PATH . DS . 'resource' . DS . 'initialize.sql');
             $adapter->execute($sql);
         }
     }
 }
예제 #3
0
 /**
  * @covers User\mappers\UserMapper::find_by_id
  */
 public function test_find_by_id()
 {
     $adapter = new \common\adapters\MysqlAdapter('users');
     $id = $adapter->select(['id'])->where(['deleted' => ['=', 0]])->limit(1)->execute()->get_result();
     self::assertTrue($this->mapper->find_by_id($id)->id > 0);
 }