9dc96805f0dda5855d63f8e425ab4b0c5f3002c2
[m6w6/pq-gateway] / tests / lib / pq / Gateway / CellTest.php
1 <?php
2
3 namespace pq\Gateway;
4
5 include __DIR__."/../../../setup.inc";
6
7 class CellTest extends \PHPUnit_Framework_TestCase {
8
9 /**
10 * @var \pq\Connection
11 */
12 protected $conn;
13
14 /**
15 * @var \pq\Gateway\Table
16 */
17 protected $table;
18
19 protected function setUp() {
20 $this->conn = new \pq\Connection(PQ_TEST_DSN);
21 $this->conn->exec(PQ_TEST_TABLE_CREATE);
22 $this->conn->exec(PQ_TEST_REFTABLE_CREATE);
23 $this->conn->exec(PQ_TEST_DATA);
24 Table::$defaultConnection = $this->conn;
25 $this->table = new Table("test");
26 $this->table->getQueryExecutor()->attach(new \QueryLogger());
27 }
28
29 protected function tearDown() {
30 $this->conn->exec(PQ_TEST_REFTABLE_DROP);
31 $this->conn->exec(PQ_TEST_TABLE_DROP);
32 }
33
34 /**
35 * This is a very bad test…
36 */
37 public function testBasic() {
38 $row = $this->table->find(null, "id desc", 1)->current();
39 foreach ($row->getData() as $key => $val) {
40 $this->assertEquals($val, (string) $row->$key);
41 $this->assertFalse($row->$key->isExpr());
42 $this->assertFalse($row->$key->isDirty());
43 $this->assertSame($val, $row->$key->get());
44 $row->$key->mod(123);
45 $this->assertNotEquals($val, (string) $row->$key);
46 $this->assertTrue($row->$key->isExpr());
47 $this->assertTrue($row->$key->isDirty());
48 $this->assertNotSame($val, $row->$key->get());
49 $this->assertEquals("$key + 123", (string) $row->$key->get());
50 $row->$key->mod("foobar");
51 $this->assertEquals("$key + 123 || 'foobar'", (string) $row->$key);
52 $row->$key->mod(new \pq\Query\Expr(" - %s()", "now"));
53 $this->assertEquals("$key + 123 || 'foobar' - now()", (string) $row->$key);
54 }
55 }
56 }