Skip to content

Commit 2292908

Browse files
committed
Upgrade to modern PHPUnit versions
1 parent e94e2ad commit 2292908

File tree

4 files changed

+76
-98
lines changed

4 files changed

+76
-98
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "2.*",
23-
"phpunit/phpunit": "5.*",
23+
"phpunit/phpunit": "^8.0 || ^9.0",
2424
"squizlabs/php_codesniffer": "3.*"
2525
},
2626
"autoload": {

tests/GeoIp2/Test/Database/ReaderTest.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,45 +84,41 @@ public function testIsInEuropeanUnion($type, $method)
8484
$reader->close();
8585
}
8686

87-
/**
88-
* @expectedException \GeoIp2\Exception\AddressNotFoundException
89-
* @expectedExceptionMessage The address 10.10.10.10 is not in the database.
90-
*/
9187
public function testUnknownAddress()
9288
{
89+
$this->expectException(\GeoIp2\Exception\AddressNotFoundException::class);
90+
$this->expectExceptionMessage('The address 10.10.10.10 is not in the database.');
91+
9392
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
9493
$reader->city('10.10.10.10');
9594
$reader->close();
9695
}
9796

98-
/**
99-
* @expectedException \BadMethodCallException
100-
* @expectedExceptionMessage The country method cannot be used to open a GeoIP2-City database
101-
*/
10297
public function testIncorrectDatabase()
10398
{
99+
$this->expectException(\BadMethodCallException::class);
100+
$this->expectExceptionMessage('The country method cannot be used to open a GeoIP2-City database');
101+
104102
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
105103
$reader->country('10.10.10.10');
106104
$reader->close();
107105
}
108106

109-
/**
110-
* @expectedException \BadMethodCallException
111-
* @expectedExceptionMessage The domain method cannot be used to open a GeoIP2-City database
112-
*/
113107
public function testIncorrectDatabaseFlat()
114108
{
109+
$this->expectException(\BadMethodCallException::class);
110+
$this->expectExceptionMessage('The domain method cannot be used to open a GeoIP2-City database');
111+
115112
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
116113
$reader->domain('10.10.10.10');
117114
$reader->close();
118115
}
119116

120-
/**
121-
* @expectedException \InvalidArgumentException
122-
* @expectedExceptionMessage is not a valid IP address
123-
*/
124117
public function testInvalidAddress()
125118
{
119+
$this->expectException(\InvalidArgumentException::class);
120+
$this->expectExceptionMessage('is not a valid IP address');
121+
126122
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
127123
$reader->city('invalid');
128124
$reader->close();

tests/GeoIp2/Test/Model/CountryTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CountryTest extends TestCase
3737

3838
private $model;
3939

40-
protected function setUp()
40+
protected function setUp(): void
4141
{
4242
$this->model = new Country($this->raw, ['en']);
4343
}
@@ -224,21 +224,19 @@ public function testIsSet()
224224
);
225225
}
226226

227-
/**
228-
* @expectedException \RuntimeException
229-
* @expectedExceptionMessage Unknown attribute
230-
*/
231227
public function testUnknownRecord()
232228
{
229+
$this->expectException(\RuntimeException::class);
230+
$this->expectExceptionMessage('Unknown attribute');
231+
233232
$this->model->unknownRecord;
234233
}
235234

236-
/**
237-
* @expectedException \RuntimeException
238-
* @expectedExceptionMessage Unknown attribute
239-
*/
240235
public function testUnknownTrait()
241236
{
237+
$this->expectException(\RuntimeException::class);
238+
$this->expectExceptionMessage('Unknown attribute');
239+
242240
$this->model->traits->unknown;
243241
}
244242
}

tests/GeoIp2/Test/WebService/ClientTest.php

Lines changed: 56 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -293,153 +293,137 @@ public function testMe()
293293
);
294294
}
295295

296-
/**
297-
* @expectedException \GeoIp2\Exception\GeoIp2Exception
298-
* @expectedExceptionMessage Received a 200 response for GeoIP2 Country but did not receive a HTTP body.
299-
*/
300296
public function testNoBodyException()
301297
{
298+
$this->expectException(\GeoIp2\Exception\GeoIp2Exception::class);
299+
$this->expectExceptionMessage('Received a 200 response for GeoIP2 Country but did not receive a HTTP body.');
300+
302301
$this->makeRequest('Country', '1.2.3.5');
303302
}
304303

305-
/**
306-
* @expectedException \GeoIp2\Exception\GeoIp2Exception
307-
* @expectedExceptionMessage Received a 200 response for GeoIP2 Country but could not decode the response as JSON:
308-
*/
309304
public function testBadBodyException()
310305
{
306+
$this->expectException(\GeoIp2\Exception\GeoIp2Exception::class);
307+
$this->expectExceptionMessage('Received a 200 response for GeoIP2 Country but could not decode the response as JSON:');
308+
311309
$this->makeRequest('Country', '2.2.3.5');
312310
}
313311

314-
/**
315-
* @expectedException \GeoIp2\Exception\InvalidRequestException
316-
* @expectedExceptionCode 400
317-
* @expectedExceptionMessage The value "1.2.3" is not a valid ip address
318-
*/
319312
public function testInvalidIPException()
320313
{
314+
$this->expectException(\GeoIp2\Exception\InvalidRequestException::class);
315+
$this->expectExceptionCode(400);
316+
$this->expectExceptionMessage('The value "1.2.3" is not a valid ip address');
317+
321318
$this->makeRequest('Country', '1.2.3.6');
322319
}
323320

324-
/**
325-
* @expectedException \GeoIp2\Exception\HttpException
326-
* @expectedExceptionCode 400
327-
* @expectedExceptionMessage with no body
328-
*/
329321
public function testNoErrorBodyIPException()
330322
{
323+
$this->expectException(\GeoIp2\Exception\HttpException::class);
324+
$this->expectExceptionCode(400);
325+
$this->expectExceptionMessage('with no body');
326+
331327
$this->makeRequest('Country', '1.2.3.7');
332328
}
333329

334-
/**
335-
* @expectedException \GeoIp2\Exception\GeoIp2Exception
336-
* @expectedExceptionMessage Error response contains JSON but it does not specify code or error keys: {"weird":42}
337-
*/
338330
public function testWeirdErrorBodyIPException()
339331
{
332+
$this->expectException(\GeoIp2\Exception\GeoIp2Exception::class);
333+
$this->expectExceptionMessage('Error response contains JSON but it does not specify code or error keys: {"weird":42}');
334+
340335
$this->makeRequest('Country', '1.2.3.8');
341336
}
342337

343-
/**
344-
* @expectedException \GeoIp2\Exception\HttpException
345-
* @expectedExceptionCode 400
346-
* @expectedExceptionMessage Received a 400 error for GeoIP2 Country but could not decode the response as JSON: Syntax error. Body: { invalid: }
347-
*/
348338
public function testInvalidErrorBodyIPException()
349339
{
340+
$this->expectException(\GeoIp2\Exception\HttpException::class);
341+
$this->expectExceptionCode(400);
342+
$this->expectExceptionMessage('Received a 400 error for GeoIP2 Country but could not decode the response as JSON: Syntax error. Body: { invalid: }');
343+
350344
$this->makeRequest('Country', '1.2.3.9');
351345
}
352346

353-
/**
354-
* @expectedException \GeoIp2\Exception\HttpException
355-
* @expectedExceptionCode 500
356-
* @expectedExceptionMessage Received a server error (500)
357-
*/
358347
public function test500PException()
359348
{
349+
$this->expectException(\GeoIp2\Exception\HttpException::class);
350+
$this->expectExceptionCode(500);
351+
$this->expectExceptionMessage('Received a server error (500)');
352+
360353
$this->makeRequest('Country', '1.2.3.10');
361354
}
362355

363-
/**
364-
* @expectedException \GeoIp2\Exception\HttpException
365-
* @expectedExceptionCode 300
366-
* @expectedExceptionMessage Received an unexpected HTTP status (300) for GeoIP2 Country
367-
*/
368356
public function test3xxException()
369357
{
358+
$this->expectException(\GeoIp2\Exception\HttpException::class);
359+
$this->expectExceptionCode(300);
360+
$this->expectExceptionMessage('Received an unexpected HTTP status (300) for GeoIP2 Country');
361+
370362
$this->makeRequest('Country', '1.2.3.11');
371363
}
372364

373-
/**
374-
* @expectedException \GeoIp2\Exception\HttpException
375-
* @expectedExceptionCode 406
376-
* @expectedExceptionMessage Received a 406 error for GeoIP2 Country with the following body: Cannot satisfy your Accept-Charset requirements
377-
*/
378365
public function test406Exception()
379366
{
367+
$this->expectException(\GeoIp2\Exception\HttpException::class);
368+
$this->expectExceptionCode(406);
369+
$this->expectExceptionMessage('Received a 406 error for GeoIP2 Country with the following body: Cannot satisfy your Accept-Charset requirements');
370+
380371
$this->makeRequest('Country', '1.2.3.12');
381372
}
382373

383-
/**
384-
* @expectedException \GeoIp2\Exception\AddressNotFoundException
385-
* @expectedExceptionMessage The address "1.2.3.13" is not in our database.
386-
*/
387374
public function testAddressNotFoundException()
388375
{
376+
$this->expectException(\GeoIp2\Exception\AddressNotFoundException::class);
377+
$this->expectExceptionMessage('The address "1.2.3.13" is not in our database.');
378+
389379
$this->makeRequest('Country', '1.2.3.13');
390380
}
391381

392-
/**
393-
* @expectedException \GeoIp2\Exception\AddressNotFoundException
394-
* @expectedExceptionMessage The address "1.2.3.14" is a private address.
395-
*/
396382
public function testAddressReservedException()
397383
{
384+
$this->expectException(\GeoIp2\Exception\AddressNotFoundException::class);
385+
$this->expectExceptionMessage('The address "1.2.3.14" is a private address.');
386+
398387
$this->makeRequest('Country', '1.2.3.14');
399388
}
400389

401-
/**
402-
* @expectedException \GeoIp2\Exception\AuthenticationException
403-
* @expectedExceptionMessage A user ID and license key are required to use this service
404-
*/
405390
public function testAuthorizationException()
406391
{
392+
$this->expectException(\GeoIp2\Exception\AuthenticationException::class);
393+
$this->expectExceptionMessage('A user ID and license key are required to use this service');
394+
407395
$this->makeRequest('Country', '1.2.3.15');
408396
}
409397

410-
/**
411-
* @expectedException \GeoIp2\Exception\AuthenticationException
412-
* @expectedExceptionMessage A license key is required to use this service
413-
*/
414398
public function testMissingLicenseKeyException()
415399
{
400+
$this->expectException(\GeoIp2\Exception\AuthenticationException::class);
401+
$this->expectExceptionMessage('A license key is required to use this service');
402+
416403
$this->makeRequest('Country', '1.2.3.16');
417404
}
418405

419-
/**
420-
* @expectedException \GeoIp2\Exception\AuthenticationException
421-
* @expectedExceptionMessage A user ID is required to use this service
422-
*/
423406
public function testMissingUserIdException()
424407
{
408+
$this->expectException(\GeoIp2\Exception\AuthenticationException::class);
409+
$this->expectExceptionMessage('A user ID is required to use this service');
410+
425411
$this->makeRequest('Country', '1.2.3.17');
426412
}
427413

428-
/**
429-
* @expectedException \GeoIp2\Exception\AuthenticationException
430-
* @expectedExceptionMessage A account ID is required to use this service
431-
*/
432414
public function testMissingAccountIdException()
433415
{
416+
$this->expectException(\GeoIp2\Exception\AuthenticationException::class);
417+
$this->expectExceptionMessage('A account ID is required to use this service');
418+
434419
$this->makeRequest('Country', '1.2.3.19');
435420
}
436421

437-
/**
438-
* @expectedException \GeoIp2\Exception\OutOfQueriesException
439-
* @expectedExceptionMessage The license key you have provided is out of queries.
440-
*/
441422
public function testOutOfQueriesException()
442423
{
424+
$this->expectException(\GeoIp2\Exception\OutOfQueriesException::class);
425+
$this->expectExceptionMessage('The license key you have provided is out of queries.');
426+
443427
$this->makeRequest('Country', '1.2.3.18');
444428
}
445429

@@ -498,8 +482,8 @@ private function makeRequest(
498482
list($statusCode, $headers, $responseBody)
499483
= $this->getResponse($service, $ipAddress);
500484

501-
$stub = $this->getMockForAbstractClass(
502-
'MaxMind\\WebService\\Http\\Request'
485+
$stub = $this->createMock(
486+
\MaxMind\WebService\Http\Request::class
503487
);
504488
$contentType = isset($headers['Content-Type'])
505489
? $headers['Content-Type']

0 commit comments

Comments
 (0)