public function __construct($conf) { if (!isset($conf['tableClass'])) { throw new Exception('new ResultSet 時必需要指定 tableClass'); } $this->_tableClass = $conf['tableClass']; $this->_table = Pix_Table::getTable($this->_tableClass); if (isset($conf['belongs_row'])) { $this->_belongs_row = $conf['belongs_row']; } $this->_search_object = Pix_Table_Search::factory(); }
public function testFind_by() { $table = Pix_Table::getTable('Pix_Table_TableTest_Table'); $db = $this->getMock('Pix_Table_Db_Adapter_Abstract', array('fetch')); Pix_Table_TableTest_Table::setDb($db); $search = Pix_Table_Search::factory(array('value' => '999'), $table)->limit(1); $db->expects($this->once())->method('fetch')->with($this->isInstanceOf('Pix_Table_TableTest_Table'), $search, '*')->will($this->returnValue(array(array('t1_id' => 8, 'value' => 999)))); $row = Pix_Table_TableTest_Table::find_by_value(999); $this->assertEquals($row->t1_id, 8); $this->assertEquals($row->value, 999); }
/** * testDelete 測試 relation 的 delete = true 要可以 work * * @access public * @return void */ public function testDelete() { $db = $this->getMock('Pix_Table_Db_Adapter_Abstract', array('deleteOne', 'fetchOne', 'fetch')); $row = new Pix_Table_Row(array('tableClass' => 'Pix_Table_TableRelationTest_Table', 'data' => array('t1_id' => 1000, 'value' => 'delete_me'))); $db->expects($this->once())->method('fetchOne')->with($this->isInstanceOf('Pix_Table_TableRelationTest_Table2'), array(1000))->will($this->returnValue(array('t2_id' => 1000, 'value' => 'foo'))); $search = Pix_Table_Search::factory(array('t3_t1id' => 1000), Pix_Table_TableRelationTest_Table3::getTable()); $db->expects($this->once())->method('fetch')->with($this->isInstanceOf('Pix_Table_TableRelationTest_Table3'), $search, '*')->will($this->returnValue(array(array('t3_id' => 9999, 't3_t1id' => 1000, 'value' => 'bar')))); $db->expects($this->exactly(3))->method('deleteOne'); Pix_Table_TableRelationTest_Table::setDb($db); Pix_Table_TableRelationTest_Table2::setDb($db); Pix_Table_TableRelationTest_Table3::setDb($db); $row->delete(); }
/** * updateOne 從 db 上更新一個 $row 的 data * * @param Pix_Table_Row $row * @param array|string $data * @access public * @return void */ public function updateOne($row, $data) { $table = $row->getTable(); $sql = 'UPDATE ' . $this->column_quote($table->getTableName()); $sql .= ' SET ' . $this->_get_set_clause($data, $table); $sql .= ' WHERE '; $sql .= $this->_get_where_clause(Pix_Table_Search::factory(array_combine($table->getPrimaryColumns(), $row->getPrimaryValues()), $table)); return $this->query($sql); }
/** * @covers Pix_Table_Search::offset */ public function testOffset() { $search = Pix_Table_Search::factory("condiction1"); $search = $search->offset(3); $this->assertEquals($search->offset(), 3); $search = $search->offset(null); $this->assertEquals($search->offset(), null); }