Ejemplo n.º 1
0
 /**
  * @covers Openbuildings\Kohana\Database_MySQL_Result::seek
  * @covers Openbuildings\Kohana\Database_MySQL_Result::__construct
  * @covers Openbuildings\Kohana\Database_MySQL_Result::__destruct
  * @covers Openbuildings\Kohana\Database_MySQL_Result::current
  */
 public function test_ArrayAccess()
 {
     $expected = array('id' => 1, 'name' => 'test1', 'description' => 'test test3', 'price' => 0.22);
     $query = new Database_Query(Database::SELECT, 'SELECT * FROM table1');
     $result = $query->execute();
     $this->assertTrue($result->seek(1));
     $result->prev();
     $current = $result->current();
     $this->assertEquals(1, $current['id']);
     $this->assertFalse($result->seek(3));
     $this->assertNotNull($result->current());
     $query = new Database_Query(Database::SELECT, 'SELECT * FROM table1');
     $result = $query->as_object()->execute();
     $this->assertEquals((object) $expected, $result->current());
     $query = new Database_Query(Database::SELECT, 'SELECT * FROM table1');
     $result = $query->as_object('Test_Mysql_Result_Object2')->execute();
     $this->assertEquals($expected['name'], $result->current()->name);
     $this->assertEquals($expected['description'], $result->current()->description);
 }
Ejemplo n.º 2
0
 /**
  * @covers Openbuildings\Kohana\Database_Result::as_array
  */
 public function test_as_array_associative()
 {
     $query = new Database_Query(Database::SELECT, 'SELECT * FROM table1');
     $result = $query->execute();
     $array = $result->as_array();
     $expected = array(array('id' => 1, 'name' => 'test1', 'description' => 'test test3', 'price' => 0.22), array('id' => 2, 'name' => 'test2', 'description' => 'test test4', 'price' => 231.99));
     $this->assertEquals($expected, $array);
     $array = $result->as_array('name');
     $expected = array('test1' => array('id' => 1, 'name' => 'test1', 'description' => 'test test3', 'price' => 0.22), 'test2' => array('id' => 2, 'name' => 'test2', 'description' => 'test test4', 'price' => 231.99));
     $this->assertEquals($expected, $array);
     $array = $result->as_array(NULL, 'description');
     $expected = array('test test3', 'test test4');
     $this->assertEquals($expected, $array);
     $array = $result->as_array('name', 'description');
     $expected = array('test1' => 'test test3', 'test2' => 'test test4');
     $this->assertEquals($expected, $array);
 }