diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/IdiormResultSetTest.php | 67 | ||||
-rw-r--r-- | test/ORMTest.php | 31 |
2 files changed, 98 insertions, 0 deletions
diff --git a/test/IdiormResultSetTest.php b/test/IdiormResultSetTest.php new file mode 100644 index 0000000..34d42a0 --- /dev/null +++ b/test/IdiormResultSetTest.php @@ -0,0 +1,67 @@ +<?php + +class IdiormResultSetTest extends PHPUnit_Framework_TestCase { + + public function testGet() { + $IdiormResultSet = new IdiormResultSet(); + $this->assertInternalType('array', $IdiormResultSet->get_results()); + } + + public function testConstructor() { + $result_set = array('item' => new stdClass); + $IdiormResultSet = new IdiormResultSet($result_set); + $this->assertSame($IdiormResultSet->get_results(), $result_set); + } + + public function testSetResultsAndGetResults() { + $result_set = array('item' => new stdClass); + $IdiormResultSet = new IdiormResultSet(); + $IdiormResultSet->set_results($result_set); + $this->assertSame($IdiormResultSet->get_results(), $result_set); + } + + public function testAsArray() { + $result_set = array('item' => new stdClass); + $IdiormResultSet = new IdiormResultSet(); + $IdiormResultSet->set_results($result_set); + $this->assertSame($IdiormResultSet->as_array(), $result_set); + } + + public function testCount() { + $result_set = array('item' => new stdClass); + $IdiormResultSet = new IdiormResultSet($result_set); + $this->assertSame($IdiormResultSet->count(), 1); + $this->assertSame(count($IdiormResultSet), 1); + } + + public function testGetIterator() { + $result_set = array('item' => new stdClass); + $IdiormResultSet = new IdiormResultSet($result_set); + $this->assertInstanceOf('ArrayIterator', $IdiormResultSet->getIterator()); + } + + public function testForeach() { + $result_set = array('item' => new stdClass); + $IdiormResultSet = new IdiormResultSet($result_set); + $return_array = array(); + foreach($IdiormResultSet as $key => $record) { + $return_array[$key] = $record; + } + $this->assertSame($result_set, $return_array); + } + + public function testCallingMethods() { + $result_set = array('item' => ORM::for_table('test'), 'item2' => ORM::for_table('test')); + $IdiormResultSet = new IdiormResultSet($result_set); + $IdiormResultSet->set('field', 'value')->set('field2', 'value'); + + foreach($IdiormResultSet as $record) { + $this->assertTrue(isset($record->field)); + $this->assertSame($record->field, 'value'); + + $this->assertTrue(isset($record->field2)); + $this->assertSame($record->field2, 'value'); + } + } + +}
\ No newline at end of file diff --git a/test/ORMTest.php b/test/ORMTest.php index 8a50479..1773d29 100644 --- a/test/ORMTest.php +++ b/test/ORMTest.php @@ -1,7 +1,18 @@ <?php +require_once 'test_classes.php'; + class ORMTest extends PHPUnit_Framework_TestCase { + public function setUp() { + // Enable logging + ORM::configure('logging', true); + + // Set up the dummy database connection + $db = new MockPDO('sqlite::memory:'); + ORM::set_db($db); + } + public function testStaticAtrributes() { $this->assertEquals('0', ORM::CONDITION_FRAGMENT); $this->assertEquals('1', ORM::CONDITION_VALUES); @@ -44,4 +55,24 @@ class ORMTest extends PHPUnit_Framework_TestCase { $this->assertFalse(isset($model['test'])); } + public function testFindResultSet() { + $result_set = ORM::for_table('test')->find_result_set(); + $this->assertInstanceOf('IdiormResultSet', $result_set); + $this->assertSame(count($result_set), 5); + } + + public function testFindResultSetByDefault() { + ORM::configure('return_result_sets', true); + + $result_set = ORM::for_table('test')->find_many(); + $this->assertInstanceOf('IdiormResultSet', $result_set); + $this->assertSame(count($result_set), 5); + + ORM::configure('return_result_sets', false); + + $result_set = ORM::for_table('test')->find_many(); + $this->assertInternalType('array', $result_set); + $this->assertSame(count($result_set), 5); + } + }
\ No newline at end of file |