Skip to content

Commit f0d13e4

Browse files
committed
Update tests suite for FETCH_CLASS method
1 parent 6b56a5d commit f0d13e4

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

tests/JSONDBTest.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class JSONDBTest extends PHPUnit_Framework_TestCase
66
{
7-
87
/**
98
* @var \JSONDB\JSONDB
109
*/
@@ -181,4 +180,54 @@ public function testExceptionIsRaisedForDuplicatePKUKOnReplace() {
181180
self::$database->connect('__phpunit_test_server', '__phpunit', '', '__phpunit_test_database');
182181
self::$database->query('__phpunit_test_table_pk.replace(2)');
183182
}
183+
184+
/**
185+
* @expectedException \JSONDB\Exception
186+
*/
187+
public function testExceptionIsRaisedForFetchClassMode() {
188+
$r = new \JSONDB\QueryResult(array(array('testVar1' => 'foo', 'testVar2' => 'bar')), self::$database);
189+
$r->setFetchMode(\JSONDB\JSONDB::FETCH_CLASS, 'FakeClass');
190+
$r->fetch();
191+
}
192+
193+
/**
194+
* @expectedException \JSONDB\Exception
195+
*/
196+
public function testExceptionIsRaisedForFetchClassMode2() {
197+
$r = new \JSONDB\QueryResult(array(array('testVar1' => 'foo', 'testVar3' => 'bar')), self::$database);
198+
$r->setFetchMode(\JSONDB\JSONDB::FETCH_CLASS, 'TestClass');
199+
$r->fetch();
200+
}
201+
202+
/**
203+
* @expectedException \JSONDB\Exception
204+
*/
205+
public function testExceptionIsRaisedForFetchClassMode3() {
206+
$r = new \JSONDB\QueryResult(array(array('testVar1' => 'foo', 'testVar4' => 'bar')), self::$database);
207+
$r->setFetchMode(\JSONDB\JSONDB::FETCH_CLASS, 'TestClass');
208+
$r->fetch();
209+
}
210+
211+
public function testFetchClassMode() {
212+
$r = new \JSONDB\QueryResult(array(array('testVar1' => 'foo', 'testVar2' => 'bar')), self::$database);
213+
$r->setFetchMode(\JSONDB\JSONDB::FETCH_CLASS, 'TestClass');
214+
$value = $r->current();
215+
$this->assertInstanceOf('TestClass', $value);
216+
}
217+
218+
public function testFetchClassMode2() {
219+
$r = new \JSONDB\QueryResult(array(array('testVar1' => 'foo', 'testVar2' => 'bar')), self::$database);
220+
$r->setFetchMode(\JSONDB\JSONDB::FETCH_CLASS, 'TestClass');
221+
$value = $r->current();
222+
$expected = new TestClass();
223+
$expected->testVar1 = 'foo';
224+
$expected->testVar2 = 'bar';
225+
$this->assertEquals($expected, $value);
226+
}
227+
}
228+
229+
class TestClass {
230+
public $testVar1;
231+
public $testVar2;
232+
private $testVar3;
184233
}

0 commit comments

Comments
 (0)