- $this->conn = new \pq\Connection(PQ_DSN);
- $this->conn->exec(PQ_TEST_DROP_TABLE);
- $this->conn->exec(PQ_TEST_CREATE_TABLE);
- $this->conn->exec(PQ_TEST_CREATE_DATA);
-
- $this->table = new Table(PQ_TEST_TABLE_NAME, $this->conn);
+ $this->conn = new \pq\Connection(PQ_TEST_DSN);
+ $this->conn->exec(PQ_TEST_SETUP_SQL);
+ Table::$defaultConnection = $this->conn;
+ $this->table = new Table("test");
+ $this->table->getQueryExecutor()->attach(new \QueryLogger());
$this->assertCount(1, $rowset);
$this->assertCount(4, $this->table->find());
}
$this->assertCount(1, $rowset);
$this->assertCount(4, $this->table->find());
}
+
+ public function testCreateFail() {
+ $this->setExpectedException("\\pq\\Exception");
+ $rowset = new Rowset($this->table);
+ $rowset->append(new Row($this->table, array("foo" => "bar"), true));
+ $rowset->create();
+ }
+ public function testUpdateFail() {
+ $this->setExpectedException("pq\\Exception");
+ $rowset = $this->table->find();
+ $rowset->apply(function($row) {
+ $row->data = new \pq\Query\Expr("die");
+ });
+ $rowset->update();
+
+ }
+
public function testDelete() {
$this->table->find()->delete();
$this->assertCount(0, $this->table->find());
}
public function testDelete() {
$this->table->find()->delete();
$this->assertCount(0, $this->table->find());
}
+ public function testDeleteFail() {
+ $this->setExpectedException("Exception");
+ $rowset = new Rowset($this->table);
+ $rowset->append(new Row($this->table, array("xx" => 0)))->delete();
+ }
+
public function testJsonSerialize() {
$json = sprintf('[{"id":"1","created":"%s","counter":"-1","number":"-1.1","data":"yesterday"}'
.',{"id":"2","created":"%s","counter":"0","number":"0","data":"today"}'
.',{"id":"3","created":"%s","counter":"1","number":"1.1","data":"tomorrow"}]',
public function testJsonSerialize() {
$json = sprintf('[{"id":"1","created":"%s","counter":"-1","number":"-1.1","data":"yesterday"}'
.',{"id":"2","created":"%s","counter":"0","number":"0","data":"today"}'
.',{"id":"3","created":"%s","counter":"1","number":"1.1","data":"tomorrow"}]',
- date("Y-m-d H:i:s", strtotime("yesterday")),
- date("Y-m-d H:i:s", strtotime("today")),
- date("Y-m-d H:i:s", strtotime("tomorrow"))
+ new \pq\DateTime("yesterday"),
+ new \pq\DateTime("today"),
+ new \pq\DateTime("tomorrow")