diff options
-rw-r--r-- | test/ORMTest.php | 2 | ||||
-rw-r--r-- | test/QueryBuilderTest.php | 11 | ||||
-rw-r--r-- | test/bootstrap.php | 40 |
3 files changed, 50 insertions, 3 deletions
diff --git a/test/ORMTest.php b/test/ORMTest.php index 1773d29..07807da 100644 --- a/test/ORMTest.php +++ b/test/ORMTest.php @@ -1,7 +1,5 @@ <?php -require_once 'test_classes.php'; - class ORMTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php new file mode 100644 index 0000000..27d0772 --- /dev/null +++ b/test/QueryBuilderTest.php @@ -0,0 +1,11 @@ +<?php + +class QueryBuilderTest extends PHPUnit_Framework_TestCase { + + public function testFindManyQuery() { + ORM::for_table('widget')->find_many(); + $expected = "SELECT * FROM `widget`"; + $this->assertEquals($expected, ORM::get_last_query()); + } + +}
\ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php index 6f42c87..da97d2f 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,3 +1,41 @@ <?php -require_once dirname(__FILE__) . '/../idiorm.php';
\ No newline at end of file +require_once dirname(__FILE__) . '/../idiorm.php'; + +/** + * + * Mock version of the PDOStatement class. + * + */ +class MockPDOStatement extends PDOStatement { + + private $current_row = 0; + /** + * Return some dummy data + */ + public function fetch($fetch_style=PDO::FETCH_BOTH, $cursor_orientation=PDO::FETCH_ORI_NEXT, $cursor_offset=0) { + if ($this->current_row == 5) { + return false; + } else { + $this->current_row++; + return array('name' => 'Fred', 'age' => 10, 'id' => '1'); + } + } +} + +/** + * + * Mock database class implementing a subset + * of the PDO API. + * + */ +class MockPDO extends PDO { + + /** + * Return a dummy PDO statement + */ + public function prepare($statement, $driver_options=array()) { + $this->last_query = new MockPDOStatement($statement); + return $this->last_query; + } +}
\ No newline at end of file |