44
55class 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