X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=tests%2Flib%2Fpq%2FGateway%2FRowsetTest.php;h=037192a38728f8eba4b78fe31c45306a19c11e42;hp=c0ff003b204df80f8bd613d3946c077d1fd2b259;hb=580991717f5e8bb237403757e2111a8d04aca616;hpb=4879955d1b86d606dc24401f26ebde9be7612fbf diff --git a/tests/lib/pq/Gateway/RowsetTest.php b/tests/lib/pq/Gateway/RowsetTest.php index c0ff003..037192a 100644 --- a/tests/lib/pq/Gateway/RowsetTest.php +++ b/tests/lib/pq/Gateway/RowsetTest.php @@ -17,16 +17,18 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { protected $table; protected function setUp() { - $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_TABLE_CREATE); + $this->conn->exec(PQ_TEST_REFTABLE_CREATE); + $this->conn->exec(PQ_TEST_DATA); + Table::$defaultConnection = $this->conn; + $this->table = new Table("test"); + $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_DROP_TABLE); + $this->conn->exec(PQ_TEST_REFTABLE_DROP); + $this->conn->exec(PQ_TEST_TABLE_DROP); } public function test__invoke() { @@ -70,6 +72,13 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { $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 testUpdate() { $rowset = $this->table->find(); @@ -83,11 +92,27 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { }); } + 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 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"}'