Skip to content

Commit 18851e1

Browse files
committed
test: use phpunit 7.5+ or 8.5+ and refactor tests
1 parent 2519499 commit 18851e1

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
include:
28-
- php: '7.0'
28+
# - php: '7.0' # phpunit 7.5+ doesn't support it
2929
- php: '7.1'
3030
- php: '7.2'
3131
- php: '7.3'

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"php": "^7.0 || ^8.0"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^6.5 || ^7.5"
29+
"phpunit/phpunit": "^7.5 || ^8.5"
3030
},
3131
"scripts": {
3232
"test": "phpunit",

tests/JWTTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function test_decode_encoded_token($key, $algo, $age, $leeway, array $pay
2222
$jwt = new JWT($key, $algo, $age, $leeway);
2323
$token = $jwt->encode($payload, $header);
2424

25-
$this->assertInternalType('string', $token);
25+
$this->assertIsString($token);
2626
$decoded = $jwt->decode($token);
27-
$this->assertInternalType('array', $decoded);
27+
$this->assertIsArray($decoded);
2828

2929
// Normalize.
3030
if (!isset($payload['exp'])) {
@@ -34,11 +34,10 @@ public function test_decode_encoded_token($key, $algo, $age, $leeway, array $pay
3434
$this->assertSame($payload, $decoded);
3535
}
3636

37-
/**
38-
* @expectedException \Ahc\Jwt\JWTException
39-
*/
4037
public function test_json_fail()
4138
{
39+
$this->expectException(\Ahc\Jwt\JWTException::class);
40+
4241
$jwt = new JWT('very^secre7');
4342

4443
try {
@@ -52,10 +51,11 @@ public function test_json_fail()
5251

5352
/**
5453
* @dataProvider data2
55-
* @expectedException \Ahc\Jwt\JWTException
5654
*/
5755
public function test_decode_fail($key, $algo, $age, $leeway, $offset, $error, $token)
5856
{
57+
$this->expectException(\Ahc\Jwt\JWTException::class);
58+
5959
$jwt = new JWT($key, $algo, $age, $leeway);
6060
$token = is_string($token) ? $token : $jwt->encode($token);
6161

@@ -79,9 +79,9 @@ public function test_rs_decode_encoded($key, $algo, $age, $leeway, array $payloa
7979
$jwt = new JWT($key, str_replace('HS', 'RS', $algo), $age, $leeway);
8080
$token = $jwt->encode($payload, $header);
8181

82-
$this->assertInternalType('string', $token);
82+
$this->assertIsString($token);
8383
$decoded = $jwt->decode($token);
84-
$this->assertInternalType('array', $decoded);
84+
$this->assertIsArray($decoded);
8585

8686
// Normalize.
8787
if (!isset($payload['exp'])) {
@@ -93,10 +93,11 @@ public function test_rs_decode_encoded($key, $algo, $age, $leeway, array $payloa
9393

9494
/**
9595
* @dataProvider data3
96-
* @expectedException \Ahc\Jwt\JWTException
9796
*/
9897
public function test_rs_invalid_key($method, $key, $arg)
9998
{
99+
$this->expectException(\Ahc\Jwt\JWTException::class);
100+
100101
$jwt = new JWT($key, 'RS256');
101102

102103
try {
@@ -121,12 +122,11 @@ public function test_kid()
121122
return $jwt;
122123
}
123124

124-
/**
125-
* @expectedException \Ahc\Jwt\JWTException
126-
* @expectedExceptionMessage Invalid token: Unknown key ID
127-
*/
128125
public function test_kid_invalid()
129126
{
127+
$this->expectException(\Ahc\Jwt\JWTException::class);
128+
$this->expectExceptionMessage('Invalid token: Unknown key ID');
129+
130130
// keys can be sent as array too
131131
$jwt = new JWT(['key1' => 'secret1', 'key2' => 'secret2'], 'HS256');
132132

0 commit comments

Comments
 (0)