public function testUpdateWithNewArray()
 {
     $new = Companies::create(array('name' => 'Acme, Inc.', 'active' => true));
     $expected = array('name' => 'Acme, Inc.', 'active' => true);
     $result = $new->data();
     $this->assertEqual($expected, $result);
     $new->foo = array('bar');
     $expected = array('name' => 'Acme, Inc.', 'active' => true, 'foo' => array('bar'));
     $result = $new->data();
     $this->assertEqual($expected, $result);
     $this->assertTrue($new->save());
     $updated = Companies::find((string) $new->_id);
     $expected = 'bar';
     $result = $updated->foo[0];
     $this->assertEqual($expected, $result);
     $updated->foo[1] = 'baz';
     $this->assertTrue($updated->save());
     $updated = Companies::find((string) $updated->_id);
     $expected = 'baz';
     $result = $updated->foo[1];
     $this->assertEqual($expected, $result);
 }
示例#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;');
 }
 public function testAbstractTypeHandling()
 {
     $key = Companies::meta('key');
     foreach ($this->companiesData as $data) {
         $companies[] = Companies::create($data);
         $this->assertTrue(end($companies)->save());
         $this->assertTrue(end($companies)->{$key});
     }
     foreach (Companies::all() as $companies) {
         $this->assertTrue($companies->delete());
     }
 }
示例#4
0
 protected static function _createCompany()
 {
     Companies::create(array('name' => 'Acme, Inc.', 'active' => true))->save();
 }
示例#5
0
 public function testCrudMulti()
 {
     $large = Companies::create(array('name' => 'BigBoxMart', 'active' => true));
     $medium = Companies::create(array('name' => 'Acme, Inc.', 'active' => true));
     $small = Companies::create(array('name' => 'Ma & Pa\'s', 'active' => true));
     foreach (array('large', 'medium', 'small') as $key) {
         $this->assertFalse(${$key}->exists());
         $this->assertTrue(${$key}->save());
         $this->assertTrue(${$key}->exists());
     }
     $this->assertEqual(3, Companies::count());
     $all = Companies::all();
     $this->assertEqual(3, $all->count());
     $match = 'BigBoxMart';
     $filter = function ($entity) use(&$match) {
         return $entity->name == $match;
     };
     foreach (array('BigBoxMart', 'Acme, Inc.', 'Ma & Pa\'s') as $match) {
         $this->assertTrue($all->first($filter)->exists());
     }
     $this->assertEqual(array(true, true, true), array_values($all->delete()));
     $this->assertEqual(0, Companies::count());
 }