@@ -66,12 +66,11 @@ public function testCategoryNotIn()
6666 $ this ->assertEquals ('select * where `price` < ? and (`category` not in (?, ?)) ' , $ builder ->toSql ());
6767 }
6868
69- /**
70- * @expectedException \timgws\QBParseException
71- * @expectedExceptionMessage Field (category) should not be an array, but it is.
72- */
7369 public function testCategoryInvalidArray ()
7470 {
71+ $ this ->expectException ('\timgws\QBParseException ' );
72+ $ this ->expectExceptionMessage ("should not be an array, but it is " );
73+
7574 $ builder = $ this ->createQueryBuilder ();
7675 $ qb = $ this ->getParserUnderTest ();
7776
@@ -160,11 +159,11 @@ public function testManyNestedQuery()
160159 //$this->assertEquals('/* This test currently fails. This should be fixed. */', $builder->toSql());
161160 }
162161
163- /**
164- * @expectedException \timgws\QBParseException
165- */
166162 public function testJSONParseException ()
167163 {
164+ $ this ->expectException ('\timgws\QBParseException ' );
165+ $ this ->expectExceptionMessage ("JSON parsing threw an error " );
166+
168167 $ builder = $ this ->createQueryBuilder ();
169168 $ qb = $ this ->getParserUnderTest ();
170169
@@ -328,12 +327,11 @@ public function testEndsNotWith()
328327 $ this ->beginsOrEndsWithTest ('ends ' , true );
329328 }
330329
331- /**
332- * @expectedException timgws\QBParseException
333- * @expectedMessage Field (price) should not be an array, but it is.
334- */
335330 public function testInputIsNotArray ()
336331 {
332+ $ this ->expectException ('\timgws\QBParseException ' );
333+ $ this ->expectExceptionMessage ("should not be an array, but it is " );
334+
337335 $ v = '1.23 ' ;
338336 $ json = '{"condition":"AND","rules":[ '
339337 .'{"id":"price","field":"price","type":"double","input":"text", '
@@ -359,53 +357,69 @@ public function testRuleHasInputAndType()
359357 $ this ->assertCount (0 , $ sqlBindings );
360358 }
361359
362- /**
363- * @expectedException \timgws\QBParseException
364- * @expectedExceptionMessage Field (price) does not exist in fields list
365- */
366360 public function testFieldNotInittedNotAllowed ()
367361 {
362+ $ this ->expectException ('\timgws\QBParseException ' );
363+ $ this ->expectExceptionMessage ("does not exist in fields list " );
364+
368365 $ builder = $ this ->createQueryBuilder ();
369366 $ qb = $ this ->getParserUnderTest (array ('this_field_is_allowed_but_is_not_present_in_the_json_string ' ));
370367 $ test = $ qb ->parse ($ this ->json1 , $ builder );
371368 }
372369
373- /**
374- * @expectedException \timgws\QBParseException
375- * @expectedExceptionMessage Field (price) should be an array, but it isn't.
376- */
377- public function testBetweenMustBeArray ($ validJSON = true )
370+ public function testBetweenMustBeArray ()
378371 {
379- $ json = '{"condition":"AND","rules":[ '
380- .'{"id":"price","field":"price","type":"double","input":"text", '
381- .'"operator":"between","value":"1"}]} ' ;
372+ $ this ->expectException ('\timgws\QBParseException ' );
373+ $ this ->expectExceptionMessage ("should be an array, but it isn't " );
382374
383- if (!$ validJSON ) {
384- $ json .= '[ ' ;
385- }
375+ $ json = $ this ->_buildJsonTestForBetween (true );
386376
387377 $ builder = $ this ->createQueryBuilder ();
388378 $ qb = $ this ->getParserUnderTest ();
389379 $ test = $ qb ->parse ($ json , $ builder );
390380 }
391381
392- /**
393- * @expectedException \timgws\QBParseException
394- * @expectedExceptionMessage JSON parsing threw an error
395- */
396382 public function testThrowExceptionInvalidJSON ()
397383 {
398- $ this ->testBetweenMustBeArray (false /*invalid json*/ );
384+ $ this ->expectException ('\timgws\QBParseException ' );
385+ $ this ->expectExceptionMessage ("JSON parsing threw an error " );
386+
387+ $ json = $ this ->_buildJsonTestForBetween (false /*invalid json */ );
388+
389+ $ builder = $ this ->createQueryBuilder ();
390+ $ qb = $ this ->getParserUnderTest ();
391+ $ test = $ qb ->parse ($ json , $ builder );
392+ }
393+
394+ /**
395+ * Build a JSON string
396+ *
397+ * @see testBetweenMustBeArray
398+ * @see testThrowExceptionInvalidJSON
399+ * @param $validJSON
400+ * @return string
401+ */
402+ private function _buildJsonTestForBetween ($ validJSON ) {
403+ $ json = '{"condition":"AND","rules":[ '
404+ .'{"id":"price","field":"price","type":"double","input":"text", '
405+ .'"operator":"between","value":"1"}]} ' ;
406+
407+ if (!$ validJSON ) {
408+ $ json .= '[ ' ;
409+ }
410+
411+ return $ json ;
399412 }
400413
401414 /**
402415 * This is a similar test to testBetweenOperator, however, this will throw an exception if
403416 * there is more then two values for the 'BETWEEN' operator.
404- *
405- * @expectedException \timgws\QBParseException
406417 */
407418 public function testBetweenOperatorThrowsException ()
408419 {
420+ $ this ->expectException ('\timgws\QBParseException ' );
421+ $ this ->expectExceptionMessage ("should be an array with only two items. " );
422+
409423 $ builder = $ this ->createQueryBuilder ();
410424 $ qb = $ this ->getParserUnderTest ();
411425
@@ -414,10 +428,12 @@ public function testBetweenOperatorThrowsException()
414428
415429 /**
416430 * @see testBetweenOperatorThrowsException
417- * @expectedException \timgws\QBParseException
418431 */
419432 public function testNotBetweenOperatorThrowsException ()
420433 {
434+ $ this ->expectException ('\timgws\QBParseException ' );
435+ $ this ->expectExceptionMessage ("should be an array with only two items. " );
436+
421437 $ builder = $ this ->createQueryBuilder ();
422438 $ qb = $ this ->getParserUnderTest ();
423439
@@ -429,11 +445,12 @@ public function testNotBetweenOperatorThrowsException()
429445 *
430446 * Make sure an exception is thrown if the JSON is valid, but after parsing,
431447 * we don't get back an object
432- *
433- * @expectedException \timgws\QBParseException
434448 */
435449 public function testArrayDoesNotParse ()
436450 {
451+ $ this ->expectException ('\timgws\QBParseException ' );
452+ $ this ->expectExceptionMessage ("The query is not valid JSON " );
453+
437454 $ builder = $ this ->createQueryBuilder ();
438455 $ qb = $ this ->getParserUnderTest ();
439456
@@ -477,8 +494,6 @@ public function testQueryContains()
477494
478495 /**
479496 * QBP should successfully parse OR conditions.
480- *
481- * @throws \timgws\QBParseException
482497 */
483498 public function testNestedOrGroup ()
484499 {
@@ -500,7 +515,6 @@ public function testNestedOrGroup()
500515 * Null check is not using isnull function instead checking = 'NULL'
501516 *
502517 * Tests for #10
503- * @throws \timgws\QBParseException
504518 */
505519 public function testIsNullBecomesNullInQuery ()
506520 {
@@ -536,11 +550,12 @@ public function testIsNullBecomesNullInQuery()
536550
537551 /**
538552 * @throws \timgws\QBParseException
539- * @expectedException \timgws\QBParseException
540- * @expectedExceptionMessage Condition can only be one of: 'and', 'or'.
541553 */
542554 public function testIncorrectCondition ()
543555 {
556+ $ this ->expectException ('\timgws\QBParseException ' );
557+ $ this ->expectExceptionMessage ("Condition can only be one of: 'and', 'or' " );
558+
544559 $ json = '{"condition":null,"rules":[
545560 {"condition":"AXOR","rules":[
546561 {"id":"geo_constituency","field":"geo_constituency","type":"string","input":"select","operator":"in","value":["Aberdeen South"]},
0 commit comments