5 include __DIR__
."/../../../setup.inc";
8 * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-03-05 at 16:08:03.
10 class TableTest
extends \PHPUnit_Framework_TestCase
{
23 * Sets up the fixture, for example, opens a network connection.
24 * This method is called before a test is executed.
26 protected function setUp() {
27 $this->conn
= new \pq\
Connection(PQ_DSN
);
28 $this->conn
->exec(PQ_TEST_DROP_TABLE
);
29 $this->conn
->exec(PQ_TEST_CREATE_TABLE
);
30 Table
::$defaultConnection = $this->conn
;
31 $this->object = new Table(PQ_TEST_TABLE_NAME
);
35 * Tears down the fixture, for example, closes a network connection.
36 * This method is called after a test is executed.
38 protected function tearDown() {
39 $this->conn
->exec(PQ_TEST_DROP_TABLE
);
43 * Creates test data in the test table
45 protected function createTestData() {
46 $this->conn
->exec(PQ_TEST_CREATE_DATA
);
50 * @covers pq\Gateway\Table::setRowsetPrototype
52 public function testSetRowsetPrototype() {
53 $prop = new \
ReflectionProperty("\\pq\\Gateway\\Table", "rowset");
54 $prop->setAccessible(true);
55 $this->assertEquals("\\pq\\Gateway\\Rowset", $prop->getValue($this->object));
56 $this->object->setRowsetPrototype(null);
57 $this->assertNull($prop->getValue($this->object));
58 $rowset = new \pq\Gateway\
Rowset($this->object);
59 $this->object->setRowsetPrototype($rowset);
60 $this->assertSame($rowset, $prop->getValue($this->object));
64 * @covers pq\Gateway\Table::getConnection
66 public function testGetConnection() {
67 $this->assertSame($this->conn
, $this->object->getConnection());
71 * @covers pq\Gateway\Table::getName
73 public function testGetName() {
74 $this->assertSame(PQ_TEST_TABLE_NAME
, $this->object->getName());
78 * @covers pq\Gateway\Table::find
80 public function testFind() {
81 $rowset = $this->object->find();
82 $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
83 $rowset = $this->object->find(array("id = " => 1));
84 $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
85 $rowset = $this->object->find(array("id = " => 0));
86 $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
87 $rowset = $this->object->find(array(array("id<" => 2), array("id>" => 2)));
88 $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
92 * @covers pq\Gateway\Table::create
94 public function testCreate() {
95 $rowset = $this->object->create(array("id" => new \pq\Query\
Expr("DEFAULT")));
96 $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
97 $this->assertCount(1, $rowset);
101 * @covers pq\Gateway\Table::update
103 public function testUpdate() {
104 $row = $this->object->create(array())->current();
106 "created" => "2013-03-03 03:03:03",
109 "data" => "this is a test",
111 $row = $this->object->update(array("id = " => $row->id
), $data)->current();
112 $data = array("id" => $row->id
->get()) +
$data;
113 $this->assertSame(array_map(function($v){return strval($v);}, $data), $row->getData());
117 * @covers pq\Gateway\Table::delete
119 public function testDelete() {
120 $this->object->delete(array("id!=" => 0));
121 $this->assertCount(0, $this->object->find());