Пример #1
0
 /**
  * Skip the test if no test database connection available.
  */
 public function skip()
 {
     $connection = 'lithium_couch_test';
     $config = Connections::get($connection, array('config' => true));
     $isAvailable = $config && Connections::get($connection)->isConnected(array('autoConnect' => true));
     $this->skipIf(!$isAvailable, "No {$connection} connection available.");
     Companies::config();
     Employees::config();
     $this->_key = Companies::key();
     $this->_database = $config['database'];
     $this->_connection = Connections::get($connection);
 }
Пример #2
0
 public function testResultSet()
 {
     Employees::config(array('meta' => array('connection' => 'test')));
     Companies::config(array('meta' => array('connection' => 'test')));
     Connections::get('test')->read('DROP TABLE IF EXISTS employees;');
     $sql = "CREATE TABLE employees (id int,title varchar(100))";
     Connections::get('test')->read($sql);
     for ($i = 1; $i < 9; $i++) {
         $sql = "INSERT INTO employees (id, title) VALUES ({$i}, 'Title {$i}')";
         Connections::get('test')->read($sql);
     }
     $employees = Employees::all();
     $cpt = 0;
     foreach ($employees as $employee) {
         $cpt++;
         $this->assertEqual($cpt, $employee->id);
     }
     $this->assertEqual(8, $cpt);
     $this->assertEqual(8, count($employees));
     Employees::reset();
     Companies::reset();
     $base = Libraries::get(true, 'resources') . '/tmp/tests';
     $this->skipIf(!is_writable($base), "Path `{$base}` is not writable.");
     Connections::add('sqlite_file', array('type' => 'database', 'adapter' => 'Sqlite3', 'database' => "{$base}/sqlite_file.sq3", 'database' => ':memory:', 'encoding' => 'UTF-8'));
     Employees::config(array('meta' => array('connection' => 'sqlite_file')));
     Companies::config(array('meta' => array('connection' => 'sqlite_file')));
     Connections::get('sqlite_file')->read('DROP TABLE IF EXISTS employees;');
     $sql = "CREATE TABLE employees (id int,title varchar(100))";
     Connections::get('sqlite_file')->read($sql);
     for ($i = 1; $i < 9; $i++) {
         $sql = "INSERT INTO employees (id, title) VALUES ({$i}, 'Title {$i}')";
         Connections::get('sqlite_file')->read($sql);
     }
     $employees = Employees::all();
     $cpt = 0;
     foreach ($employees as $employee) {
         $cpt++;
         $this->assertEqual($cpt, $employee->id);
     }
     $this->assertEqual(8, $cpt);
     $this->assertEqual(8, count($employees));
     $this->_cleanUp();
     Connections::get('test')->read('DROP TABLE employees;');
     Connections::get('sqlite_file')->read('DROP TABLE employees;');
 }