-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ResultSet functionality to Idiorm
- Loading branch information
1 parent
5f2fbc8
commit 5a6d20c
Showing
6 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters