autoload; cache; tests;
[m6w6/pq-gateway] / tests / lib / pq / Gateway / TableTest.php
index bee7bddcaa93f9fd4888ca12190b4e30082e2207..a5fb56f6acb39cb3485b1d03b1ac14c53d4e284b 100644 (file)
@@ -2,11 +2,8 @@
 
 namespace pq\Gateway;
 
-include __DIR__."/../../../setup.inc";
+include_once __DIR__."/../../../setup.inc";
 
-/**
- * Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-03-05 at 16:08:03.
- */
 class TableTest extends \PHPUnit_Framework_TestCase {
 
        /**
@@ -17,108 +14,73 @@ class TableTest extends \PHPUnit_Framework_TestCase {
        /**
         * @var Table
         */
-       protected $object;
+       protected $table;
 
-       /**
-        * Sets up the fixture, for example, opens a network connection.
-        * This method is called before a test is executed.
-        */
        protected function setUp() {
-               $this->conn = new \pq\Connection(PQ_DSN);
-               $this->conn->exec(PQ_TEST_DROP_TABLE);
-               $this->conn->exec(PQ_TEST_CREATE_TABLE);
+               $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);
                Table::$defaultConnection = $this->conn;
-               $this->object = new Table(PQ_TEST_TABLE_NAME);
+               $this->table = new Table("test");
        }
 
-       /**
-        * Tears down the fixture, for example, closes a network connection.
-        * This method is called after a test is executed.
-        */
        protected function tearDown() {
-               $this->conn->exec(PQ_TEST_DROP_TABLE);
+               $this->conn->exec(PQ_TEST_REFTABLE_DROP);
+               $this->conn->exec(PQ_TEST_TABLE_DROP);
        }
        
-       /**
-        * Creates test data in the test table
-        */
-       protected function createTestData() {
-               $this->conn->exec(PQ_TEST_CREATE_DATA);
-       }
-
-       /**
-        * @covers pq\Gateway\Table::setRowsetPrototype
-        */
        public function testSetRowsetPrototype() {
                $prop = new \ReflectionProperty("\\pq\\Gateway\\Table", "rowset");
                $prop->setAccessible(true);
-               $this->assertEquals("\\pq\\Gateway\\Rowset", $prop->getValue($this->object));
-               $this->object->setRowsetPrototype(null);
-               $this->assertNull($prop->getValue($this->object));
-               $rowset = new \pq\Gateway\Rowset($this->object);
-               $this->object->setRowsetPrototype($rowset);
-               $this->assertSame($rowset, $prop->getValue($this->object));
+               $this->assertEquals("\\pq\\Gateway\\Rowset", $prop->getValue($this->table));
+               $this->table->setRowsetPrototype(null);
+               $this->assertNull($prop->getValue($this->table));
+               $rowset = new \pq\Gateway\Rowset($this->table);
+               $this->table->setRowsetPrototype($rowset);
+               $this->assertSame($rowset, $prop->getValue($this->table));
        }
 
-       /**
-        * @covers pq\Gateway\Table::getConnection
-        */
        public function testGetConnection() {
-               $this->assertSame($this->conn, $this->object->getConnection());
+               $this->assertSame($this->conn, $this->table->getConnection());
        }
 
-       /**
-        * @covers pq\Gateway\Table::getName
-        */
        public function testGetName() {
-               $this->assertSame(PQ_TEST_TABLE_NAME, $this->object->getName());
+               $this->assertSame("test", $this->table->getName());
        }
 
-       /**
-        * @covers pq\Gateway\Table::find
-        */
        public function testFind() {
-               $rowset = $this->object->find();
+               $rowset = $this->table->find();
                $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
-               $rowset = $this->object->find(array("id = " => 1));
+               $rowset = $this->table->find(array("id = " => 1));
                $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
-               $rowset = $this->object->find(array("id = " => 0));
+               $rowset = $this->table->find(array("id = " => 0));
                $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
-               $rowset = $this->object->find(array(array("id<" => 2), array("id>" => 2)));
+               $rowset = $this->table->find(array(array("id<" => 2), array("id>" => 2)));
                $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
        }
 
-       /**
-        * @covers pq\Gateway\Table::create
-        */
        public function testCreate() {
-               $rowset = $this->object->create(array("id" => new \pq\Query\Expr("DEFAULT")));
+               $rowset = $this->table->create(array("id" => new \pq\Query\Expr("DEFAULT")));
                $this->assertInstanceOf("\\pq\\Gateway\\Rowset", $rowset);
                $this->assertCount(1, $rowset);
        }
 
-       /**
-        * @covers pq\Gateway\Table::update
-        */
        public function testUpdate() {
-               $row = $this->object->create(array())->current();
+               $row = $this->table->create(array())->current();
                $data = array(
                        "created" => "2013-03-03 03:03:03",
                        "counter" => 2,
                        "number" => 2.2,
                        "data" => "this is a test",
                );
-               $row = $this->object->update(array("id = " => $row->id), $data)->current();
+               $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());
        }
 
-       /**
-        * @covers pq\Gateway\Table::delete
-        */
        public function testDelete() {
-               $this->object->delete(array("id!=" => 0));
-               $this->assertCount(0, $this->object->find());
+               $this->table->delete(array("id!=" => 0));
+               $this->assertCount(0, $this->table->find());
        }
-
 }