autoload; cache; tests;
[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 }
27
28 protected function tearDown() {
29 $this->conn->exec(PQ_TEST_REFTABLE_DROP);
30 $this->conn->exec(PQ_TEST_TABLE_DROP);
31 }
32
33 /**
34 * This is a very bad test…
35 */
36 public function testBasic() {
37 $row = $this->table->find(null, "id desc", 1)->current();
38 foreach ($row->getData() as $key => $val) {
39 $this->assertEquals($val, (string) $row->$key);
40 $this->assertFalse($row->$key->isExpr());
41 $this->assertFalse($row->$key->isDirty());
42 $this->assertSame($val, $row->$key->get());
43 $row->$key->mod(123);
44 $this->assertNotEquals($val, (string) $row->$key);
45 $this->assertTrue($row->$key->isExpr());
46 $this->assertTrue($row->$key->isDirty());
47 $this->assertNotSame($val, $row->$key->get());
48 $this->assertEquals("$key + 123", (string) $row->$key->get());
49 $row->$key->mod("foobar");
50 $this->assertEquals("$key + 123 || 'foobar'", (string) $row->$key);
51 $row->$key->mod(new \pq\Query\Expr(" - %s()", "now"));
52 $this->assertEquals("$key + 123 || 'foobar' - now()", (string) $row->$key);
53 }
54 }
55 }