X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fpq-gateway;a=blobdiff_plain;f=tests%2Flib%2Fpq%2FGateway%2FRowsetTest.php;h=61f6b11af4668fa1b30c8e8566b47eba8de6cfa9;hp=037192a38728f8eba4b78fe31c45306a19c11e42;hb=80c4d645e1650304b1dbcae85dbf17a6593896e4;hpb=580991717f5e8bb237403757e2111a8d04aca616 diff --git a/tests/lib/pq/Gateway/RowsetTest.php b/tests/lib/pq/Gateway/RowsetTest.php index 037192a..61f6b11 100644 --- a/tests/lib/pq/Gateway/RowsetTest.php +++ b/tests/lib/pq/Gateway/RowsetTest.php @@ -18,17 +18,14 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { protected function setUp() { $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); + $this->conn->exec(PQ_TEST_SETUP_SQL); Table::$defaultConnection = $this->conn; $this->table = new Table("test"); $this->table->getQueryExecutor()->attach(new \QueryLogger()); } protected function tearDown() { - $this->conn->exec(PQ_TEST_REFTABLE_DROP); - $this->conn->exec(PQ_TEST_TABLE_DROP); + $this->conn->exec(PQ_TEST_TEARDOWN_SQL); } public function test__invoke() { @@ -74,7 +71,7 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { } public function testCreateFail() { - $this->setExpectedException("\\pq\\Exception"); + $this->setExpectedException("\\OutOfBoundsException"); $rowset = new Rowset($this->table); $rowset->append(new Row($this->table, array("foo" => "bar"), true)); $rowset->create(); @@ -114,12 +111,16 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { } 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")) + $yday = new \pq\DateTime("yesterday"); + $tday = new \pq\DateTime("today"); + $tmrw = new \pq\DateTime("tomorrow"); + + $yday->format = $tday->format = $tmrw->format = "Y-m-d H:i:s.u"; + + $json = sprintf('[{"id":1,"created":"%s","counter":-1,"number":-1.1,"data":"yesterday","list":[-1,0,1],"prop":null}' + .',{"id":2,"created":"%s","counter":0,"number":0,"data":"today","list":[0,1,2],"prop":null}' + .',{"id":3,"created":"%s","counter":1,"number":1.1,"data":"tomorrow","list":[1,2,3],"prop":null}]', + $yday, $tday, $tmrw ); $this->assertJsonStringEqualsJsonString($json, json_encode($this->table->find())); } @@ -158,4 +159,14 @@ class RowsetTest extends \PHPUnit_Framework_TestCase { $this->assertSame(array(), $rowset3->getRows()); $this->assertCount(1, $rowset->filter(function($row) { return $row->id->get() == 1; })); } + + public function testApplyAppend() { + $rowset1 = $this->table->find(null, null, 1); + $rowset2 = $this->table->find(null, null, 1, 1); + $this->assertCount(1, $rowset1); + $this->assertCount(1, $rowset2); + $rowset2->apply(array($rowset1, "append")); + $this->assertCount(1, $rowset2); + $this->assertCount(2, $rowset1); + } }