Skip to content

Commit 8cc6552

Browse files
committed
fix for old phpunit
1 parent a083e49 commit 8cc6552

File tree

1 file changed

+85
-17
lines changed

1 file changed

+85
-17
lines changed

tests/JWTTest.php

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,31 @@ public function testUrlSafeCharacters()
3131

3232
public function testMalformedUtf8StringsFail()
3333
{
34-
$this->expectException('DomainException');
34+
if (version_compare(PHP_VERSION, '5.6', '<')) {
35+
$this->setExpectedException('DomainException');
36+
} else {
37+
$this->expectException('DomainException');
38+
}
3539
JWT::encode(pack('c', 128), 'a');
3640
}
3741

3842
public function testMalformedJsonThrowsException()
3943
{
40-
$this->expectException('DomainException');
44+
if (version_compare(PHP_VERSION, '5.6', '<')) {
45+
$this->setExpectedException('DomainException');
46+
} else {
47+
$this->expectException('DomainException');
48+
}
4149
JWT::jsonDecode('this is not valid JSON string');
4250
}
4351

4452
public function testExpiredToken()
4553
{
46-
$this->expectException('Firebase\JWT\ExpiredException');
54+
if (version_compare(PHP_VERSION, '5.6', '<')) {
55+
$this->setExpectedException('Firebase\JWT\ExpiredException');
56+
} else {
57+
$this->expectException('Firebase\JWT\ExpiredException');
58+
}
4759
$payload = array(
4860
"message" => "abc",
4961
"exp" => time() - 20); // time in the past
@@ -53,7 +65,11 @@ public function testExpiredToken()
5365

5466
public function testBeforeValidTokenWithNbf()
5567
{
56-
$this->expectException('Firebase\JWT\BeforeValidException');
68+
if (version_compare(PHP_VERSION, '5.6', '<')) {
69+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
70+
} else {
71+
$this->expectException('Firebase\JWT\BeforeValidException');
72+
}
5773
$payload = array(
5874
"message" => "abc",
5975
"nbf" => time() + 20); // time in the future
@@ -63,7 +79,11 @@ public function testBeforeValidTokenWithNbf()
6379

6480
public function testBeforeValidTokenWithIat()
6581
{
66-
$this->expectException('Firebase\JWT\BeforeValidException');
82+
if (version_compare(PHP_VERSION, '5.6', '<')) {
83+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
84+
} else {
85+
$this->expectException('Firebase\JWT\BeforeValidException');
86+
}
6787
$payload = array(
6888
"message" => "abc",
6989
"iat" => time() + 20); // time in the future
@@ -99,7 +119,11 @@ public function testExpiredTokenWithLeeway()
99119
$payload = array(
100120
"message" => "abc",
101121
"exp" => time() - 70); // time far in the past
102-
$this->expectException('Firebase\JWT\ExpiredException');
122+
if (version_compare(PHP_VERSION, '5.6', '<')) {
123+
$this->setExpectedException('Firebase\JWT\ExpiredException');
124+
} else {
125+
$this->expectException('Firebase\JWT\ExpiredException');
126+
}
103127
$encoded = JWT::encode($payload, 'my_key');
104128
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
105129
$this->assertEquals($decoded->message, 'abc');
@@ -147,7 +171,11 @@ public function testInvalidTokenWithNbfLeeway()
147171
"message" => "abc",
148172
"nbf" => time() + 65); // not before too far in future
149173
$encoded = JWT::encode($payload, 'my_key');
150-
$this->expectException('Firebase\JWT\BeforeValidException');
174+
if (version_compare(PHP_VERSION, '5.6', '<')) {
175+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
176+
} else {
177+
$this->expectException('Firebase\JWT\BeforeValidException');
178+
}
151179
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
152180
JWT::$leeway = 0;
153181
}
@@ -171,7 +199,11 @@ public function testInvalidTokenWithIatLeeway()
171199
"message" => "abc",
172200
"iat" => time() + 65); // issued too far in future
173201
$encoded = JWT::encode($payload, 'my_key');
174-
$this->expectException('Firebase\JWT\BeforeValidException');
202+
if (version_compare(PHP_VERSION, '5.6', '<')) {
203+
$this->setExpectedException('Firebase\JWT\BeforeValidException');
204+
} else {
205+
$this->expectException('Firebase\JWT\BeforeValidException');
206+
}
175207
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
176208
JWT::$leeway = 0;
177209
}
@@ -182,7 +214,11 @@ public function testInvalidToken()
182214
"message" => "abc",
183215
"exp" => time() + 20); // time in the future
184216
$encoded = JWT::encode($payload, 'my_key');
185-
$this->expectException('Firebase\JWT\SignatureInvalidException');
217+
if (version_compare(PHP_VERSION, '5.6', '<')) {
218+
$this->setExpectedException('Firebase\JWT\SignatureInvalidException');
219+
} else {
220+
$this->expectException('Firebase\JWT\SignatureInvalidException');
221+
}
186222
$decoded = JWT::decode($encoded, 'my_key2', array('HS256'));
187223
}
188224

@@ -192,7 +228,11 @@ public function testNullKeyFails()
192228
"message" => "abc",
193229
"exp" => time() + JWT::$leeway + 20); // time in the future
194230
$encoded = JWT::encode($payload, 'my_key');
195-
$this->expectException('InvalidArgumentException');
231+
if (version_compare(PHP_VERSION, '5.6', '<')) {
232+
$this->setExpectedException('InvalidArgumentException');
233+
} else {
234+
$this->expectException('InvalidArgumentException');
235+
}
196236
$decoded = JWT::decode($encoded, null, array('HS256'));
197237
}
198238

@@ -202,7 +242,11 @@ public function testEmptyKeyFails()
202242
"message" => "abc",
203243
"exp" => time() + JWT::$leeway + 20); // time in the future
204244
$encoded = JWT::encode($payload, 'my_key');
205-
$this->expectException('InvalidArgumentException');
245+
if (version_compare(PHP_VERSION, '5.6', '<')) {
246+
$this->setExpectedException('InvalidArgumentException');
247+
} else {
248+
$this->expectException('InvalidArgumentException');
249+
}
206250
$decoded = JWT::decode($encoded, '', array('HS256'));
207251
}
208252

@@ -237,21 +281,33 @@ public function testArrayAccessKIDChooser()
237281
public function testNoneAlgorithm()
238282
{
239283
$msg = JWT::encode('abc', 'my_key');
240-
$this->expectException('UnexpectedValueException');
284+
if (version_compare(PHP_VERSION, '5.6', '<')) {
285+
$this->setExpectedException('UnexpectedValueException');
286+
} else {
287+
$this->expectException('UnexpectedValueException');
288+
}
241289
JWT::decode($msg, 'my_key', array('none'));
242290
}
243291

244292
public function testIncorrectAlgorithm()
245293
{
246294
$msg = JWT::encode('abc', 'my_key');
247-
$this->expectException('UnexpectedValueException');
295+
if (version_compare(PHP_VERSION, '5.6', '<')) {
296+
$this->setExpectedException('UnexpectedValueException');
297+
} else {
298+
$this->expectException('UnexpectedValueException');
299+
}
248300
JWT::decode($msg, 'my_key', array('RS256'));
249301
}
250302

251303
public function testMissingAlgorithm()
252304
{
253305
$msg = JWT::encode('abc', 'my_key');
254-
$this->expectException('UnexpectedValueException');
306+
if (version_compare(PHP_VERSION, '5.6', '<')) {
307+
$this->setExpectedException('UnexpectedValueException');
308+
} else {
309+
$this->expectException('UnexpectedValueException');
310+
}
255311
JWT::decode($msg, 'my_key');
256312
}
257313

@@ -263,20 +319,32 @@ public function testAdditionalHeaders()
263319

264320
public function testInvalidSegmentCount()
265321
{
266-
$this->expectException('UnexpectedValueException');
322+
if (version_compare(PHP_VERSION, '5.6', '<')) {
323+
$this->setExpectedException('UnexpectedValueException');
324+
} else {
325+
$this->expectException('UnexpectedValueException');
326+
}
267327
JWT::decode('brokenheader.brokenbody', 'my_key', array('HS256'));
268328
}
269329

270330
public function testInvalidSignatureEncoding()
271331
{
272332
$msg = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwibmFtZSI6ImZvbyJ9.Q4Kee9E8o0Xfo4ADXvYA8t7dN_X_bU9K5w6tXuiSjlUxx";
273-
$this->expectException('UnexpectedValueException');
333+
if (version_compare(PHP_VERSION, '5.6', '<')) {
334+
$this->setExpectedException('UnexpectedValueException');
335+
} else {
336+
$this->expectException('UnexpectedValueException');
337+
}
274338
JWT::decode($msg, 'secret', array('HS256'));
275339
}
276340

277341
public function testVerifyError()
278342
{
279-
$this->expectException('DomainException');
343+
if (version_compare(PHP_VERSION, '5.6', '<')) {
344+
$this->setExpectedException('DomainException');
345+
} else {
346+
$this->expectException('DomainException');
347+
}
280348
$pkey = openssl_pkey_new();
281349
$msg = JWT::encode('abc', $pkey, 'RS256');
282350
self::$opensslVerifyReturnValue = -1;

0 commit comments

Comments
 (0)