{
- "name": "mike_php_net/pq-gateway",
- "type": "library",
- "description": "Table/row gateway for ext-pq",
- "keywords": ["postgres", "orm", "gateway", "pq"],
- "homepage": "http://bitbucket.org/mike_php_net/pq-gateway",
- "license": "BSD-2-Clause",
- "authors": [
- {
- "name": "Michael Wallner",
- "email": "mike@php.net"
- }
- ],
- "autoload": {
- "psr-0": {
- "pq\\Gateway": "lib",
- "pq\\Query": "lib"
- }
- },
- "suggest": {
- "reactphp/promise": "1.0.*"
- }
+ "name": "mike_php_net/pq-gateway",
+ "type": "library",
+ "description": "Table/row gateway for ext-pq",
+ "keywords": ["postgres", "orm", "gateway", "pq"],
+ "homepage": "http://bitbucket.org/mike_php_net/pq-gateway",
+ "license": "BSD-2-Clause",
+ "authors": [
+ {
+ "name": "Michael Wallner",
+ "email": "mike@php.net"
+ }
+ ],
+ "autoload": {
+ "psr-0": {
+ "pq\\Gateway": "lib",
+ "pq\\Query": "lib"
+ }
+ },
+ "suggest": {
+ "reactphp/promise": "1.0.*"
+ }
}
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);
}
/**
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);
}
function testBasic() {
$row = new Row($this->table, array("id" => 3), true);
$this->assertTrue($row->isDirty());
$row->refresh();
- $this->assertSame(
+ $this->assertEquals(
array(
"id" => "3",
- "created" => date("Y-m-d H:i:s", strtotime("tomorrow")),
+ "created" => new \pq\DateTime("tomorrow"),
"counter" => "1",
"number" => "1.1",
"data" => "tomorrow"
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() {
$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")
);
$this->assertJsonStringEqualsJsonString($json, json_encode($this->table->find()));
}
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 testSetRowsetPrototype() {
public function testUpdate() {
$row = $this->table->create(array())->current();
$data = array(
- "created" => "2013-03-03 03:03:03",
+ "created" => new \pq\DateTime("2013-03-03 03:03:03"),
"counter" => 2,
"number" => 2.2,
"data" => "this is a test",
);
$row = $this->table->update(array("id = " => $row->id), $data)->current();
$data = array("id" => $row->id->get()) + $data;
- $this->assertSame(array_map(function($v){return strval($v);}, $data), $row->getData());
+ $this->assertEquals(array_map(function($v){return strval($v);}, $data), $row->getData());
}
public function testDelete() {
$this->assertCount(1, $rowset);
$this->assertEquals(array(
"id" => 2,
- "created" => date_create("today")->format("Y-m-d H:i:s"),
+ "created" => new \pq\DateTime("today"),
"counter" => 0,
"number" => 0,
"data" => "today"
const PQ_TEST_DSN = "";
-const PQ_TEST_TABLE_CREATE = <<<SQL
+const PQ_TEST_SETUP_SQL = <<<SQL
drop table if exists test cascade;
create table test (
id serial primary key,
counter int,
number decimal,
data text
- )
-SQL;
-
-const PQ_TEST_TABLE_DROP = <<<SQL
- drop table if exists test cascade;
-SQL;
-
-const PQ_TEST_REFTABLE_CREATE = <<<SQL
+ );
+
drop table if exists reftest cascade;
create table reftest (
test_id integer not null references test on delete cascade,
another_test_id integer not null references test on delete cascade
);
-SQL;
-
-const PQ_TEST_REFTABLE_DROP = <<<SQL
- drop table if exists reftest cascade;
-SQL;
-
-const PQ_TEST_DATA = <<<SQL
+
insert into test values (default, 'yesterday', -1, -1.1, 'yesterday');
insert into test values (default, 'today', 0, 0, 'today');
insert into test values (default, 'tomorrow', 1, 1.1, 'tomorrow');
insert into reftest values (3,1);
SQL;
-spl_autoload_register(function($c) {
- if (substr($c,0,3) == "pq\\") return require_once sprintf("%s/../lib/%s.php", __DIR__, strtr($c, "\\", "/"));
-});
+const PQ_TEST_TEARDOWN_SQL = <<<SQL
+ drop table if exists test cascade;
+ drop table if exists reftest cascade;
+SQL;
+
+include_once __DIR__ . "/../lib/autoload.php";
function executeInConcurrentTransaction(\pq\Query\ExecutorInterface $exec, $sql, array $params = null) {
$conn = $exec->getConnection();