Skip to content

Commit f62bbf9

Browse files
authored
Travis should use PHP 7.2, support PHPUnit 8.3/7.0 (#43)
1 parent b0b5624 commit f62bbf9

6 files changed

Lines changed: 74 additions & 74 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: php
22
php:
3-
- 7.1
3+
- 7.2
44
before_script:
55
- composer self-update
66
- composer require satooshi/php-coveralls

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"jenssegers/mongodb": "Use QueryBuilderParser with MongoDB"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^7.0",
31-
"mockery/mockery": "^0.9.4"
30+
"phpunit/phpunit": "^8.3|^7.0",
31+
"mockery/mockery": "^1.2.3|^0.9.4"
3232
}
3333
}

tests/CommonQueryBuilderTests.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ class CommonQueryBuilderTests extends TestCase
4444
]
4545
}';
4646

47-
protected function setUp()
48-
{
49-
}
50-
5147
protected function getParserUnderTest($fields = null)
5248
{
5349
return new QueryBuilderParser($fields);

tests/JoinSupportingQueryBuilderParserTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,19 @@ public function testJoinIsNotNull()
187187
$builder->toSql());
188188
}
189189

190-
/**
191-
* @expectedException timgws\QBParseException
192-
* @expectedExceptionMessage s2_value should be an array with only two items.
193-
*
194-
* @throws \timgws\QBParseException
195-
*/
196190
public function testJoinNotExistsBetweenWithThreeItems()
197191
{
192+
$this->expectException('\timgws\QBParseException');
193+
$this->expectExceptionMessage("should be an array with only two items");
194+
198195
$this->_testJoinNotExistsBetweenWithThreeItems(false);
199196
}
200197

201-
/**
202-
* @expectedException timgws\QBParseException
203-
* @expectedExceptionMessage s2_value should be an array with only two items.
204-
*
205-
* @throws \timgws\QBParseException
206-
*/
207198
public function testJoinNotExistsNotBetweenWithThreeItems()
208199
{
200+
$this->expectException('\timgws\QBParseException');
201+
$this->expectExceptionMessage("should be an array with only two items");
202+
209203
$this->_testJoinNotExistsBetweenWithThreeItems(true);
210204
}
211205

@@ -228,14 +222,11 @@ private function _testJoinNotExistsBetweenWithThreeItems($not_between = false)
228222
$builder->toSql());
229223
}
230224

231-
/**
232-
* @expectedException timgws\QBParseException
233-
* @expectedExceptionMessage Field (join4) does not exist in fields list
234-
*
235-
* @throws \timgws\QBParseException
236-
*/
237225
public function testJoinNotExistsBetweenWithFieldThatDoesNotExist()
238226
{
227+
$this->expectException('\timgws\QBParseException');
228+
$this->expectExceptionMessage("does not exist in fields list");
229+
239230
$json = '{"condition":"AND","rules":[{"id":"join4","field":"join4","type":"text","input":"select","operator":"between","value":["a","b","c"]}]}';
240231

241232
$builder = $this->createQueryBuilder();

tests/QBPFunctionsTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ protected static function getMethod($name) {
2020
return $method;
2121
}
2222

23-
/**
24-
* @expectedException \timgws\QBParseException
25-
* @expectedExceptionMessage makeQueryWhenArray could not return a value
26-
*/
2723
public function testOperatorNotValid()
2824
{
25+
$this->expectException('\timgws\QBParseException');
26+
$this->expectExceptionMessage("makeQueryWhenArray could not return a value");
27+
2928
$method = self::getMethod('makeQueryWhenArray');
3029

3130
$builder = $this->createQueryBuilder();
@@ -37,12 +36,11 @@ public function testOperatorNotValid()
3736
]);
3837
}
3938

40-
/**
41-
* @expectedException \timgws\QBParseException
42-
* @expectedExceptionMessage makeQueryWhenNull was called on an SQL operator that is not null
43-
*/
4439
public function testOperatorNotValidForNull()
4540
{
41+
$this->expectException('\timgws\QBParseException');
42+
$this->expectExceptionMessage("makeQueryWhenNull was called on an SQL operator that is not null");
43+
4644
$method = self::getMethod('makeQueryWhenNull');
4745

4846
$builder = $this->createQueryBuilder();

tests/QueryBuilderParserTest.php

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)