@@ -31,19 +31,31 @@ public function testUrlSafeCharacters()
31
31
32
32
public function testMalformedUtf8StringsFail ()
33
33
{
34
- $ this ->expectException ('DomainException ' );
34
+ if (version_compare (PHP_VERSION , '5.6 ' , '< ' )) {
35
+ $ this ->setExpectedException ('DomainException ' );
36
+ } else {
37
+ $ this ->expectException ('DomainException ' );
38
+ }
35
39
JWT ::encode (pack ('c ' , 128 ), 'a ' );
36
40
}
37
41
38
42
public function testMalformedJsonThrowsException ()
39
43
{
40
- $ this ->expectException ('DomainException ' );
44
+ if (version_compare (PHP_VERSION , '5.6 ' , '< ' )) {
45
+ $ this ->setExpectedException ('DomainException ' );
46
+ } else {
47
+ $ this ->expectException ('DomainException ' );
48
+ }
41
49
JWT ::jsonDecode ('this is not valid JSON string ' );
42
50
}
43
51
44
52
public function testExpiredToken ()
45
53
{
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
+ }
47
59
$ payload = array (
48
60
"message " => "abc " ,
49
61
"exp " => time () - 20 ); // time in the past
@@ -53,7 +65,11 @@ public function testExpiredToken()
53
65
54
66
public function testBeforeValidTokenWithNbf ()
55
67
{
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
+ }
57
73
$ payload = array (
58
74
"message " => "abc " ,
59
75
"nbf " => time () + 20 ); // time in the future
@@ -63,7 +79,11 @@ public function testBeforeValidTokenWithNbf()
63
79
64
80
public function testBeforeValidTokenWithIat ()
65
81
{
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
+ }
67
87
$ payload = array (
68
88
"message " => "abc " ,
69
89
"iat " => time () + 20 ); // time in the future
@@ -99,7 +119,11 @@ public function testExpiredTokenWithLeeway()
99
119
$ payload = array (
100
120
"message " => "abc " ,
101
121
"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
+ }
103
127
$ encoded = JWT ::encode ($ payload , 'my_key ' );
104
128
$ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
105
129
$ this ->assertEquals ($ decoded ->message , 'abc ' );
@@ -147,7 +171,11 @@ public function testInvalidTokenWithNbfLeeway()
147
171
"message " => "abc " ,
148
172
"nbf " => time () + 65 ); // not before too far in future
149
173
$ 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
+ }
151
179
$ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
152
180
JWT ::$ leeway = 0 ;
153
181
}
@@ -171,7 +199,11 @@ public function testInvalidTokenWithIatLeeway()
171
199
"message " => "abc " ,
172
200
"iat " => time () + 65 ); // issued too far in future
173
201
$ 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
+ }
175
207
$ decoded = JWT ::decode ($ encoded , 'my_key ' , array ('HS256 ' ));
176
208
JWT ::$ leeway = 0 ;
177
209
}
@@ -182,7 +214,11 @@ public function testInvalidToken()
182
214
"message " => "abc " ,
183
215
"exp " => time () + 20 ); // time in the future
184
216
$ 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
+ }
186
222
$ decoded = JWT ::decode ($ encoded , 'my_key2 ' , array ('HS256 ' ));
187
223
}
188
224
@@ -192,7 +228,11 @@ public function testNullKeyFails()
192
228
"message " => "abc " ,
193
229
"exp " => time () + JWT ::$ leeway + 20 ); // time in the future
194
230
$ 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
+ }
196
236
$ decoded = JWT ::decode ($ encoded , null , array ('HS256 ' ));
197
237
}
198
238
@@ -202,7 +242,11 @@ public function testEmptyKeyFails()
202
242
"message " => "abc " ,
203
243
"exp " => time () + JWT ::$ leeway + 20 ); // time in the future
204
244
$ 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
+ }
206
250
$ decoded = JWT ::decode ($ encoded , '' , array ('HS256 ' ));
207
251
}
208
252
@@ -237,21 +281,33 @@ public function testArrayAccessKIDChooser()
237
281
public function testNoneAlgorithm ()
238
282
{
239
283
$ 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
+ }
241
289
JWT ::decode ($ msg , 'my_key ' , array ('none ' ));
242
290
}
243
291
244
292
public function testIncorrectAlgorithm ()
245
293
{
246
294
$ 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
+ }
248
300
JWT ::decode ($ msg , 'my_key ' , array ('RS256 ' ));
249
301
}
250
302
251
303
public function testMissingAlgorithm ()
252
304
{
253
305
$ 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
+ }
255
311
JWT ::decode ($ msg , 'my_key ' );
256
312
}
257
313
@@ -263,20 +319,32 @@ public function testAdditionalHeaders()
263
319
264
320
public function testInvalidSegmentCount ()
265
321
{
266
- $ this ->expectException ('UnexpectedValueException ' );
322
+ if (version_compare (PHP_VERSION , '5.6 ' , '< ' )) {
323
+ $ this ->setExpectedException ('UnexpectedValueException ' );
324
+ } else {
325
+ $ this ->expectException ('UnexpectedValueException ' );
326
+ }
267
327
JWT ::decode ('brokenheader.brokenbody ' , 'my_key ' , array ('HS256 ' ));
268
328
}
269
329
270
330
public function testInvalidSignatureEncoding ()
271
331
{
272
332
$ 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
+ }
274
338
JWT ::decode ($ msg , 'secret ' , array ('HS256 ' ));
275
339
}
276
340
277
341
public function testVerifyError ()
278
342
{
279
- $ this ->expectException ('DomainException ' );
343
+ if (version_compare (PHP_VERSION , '5.6 ' , '< ' )) {
344
+ $ this ->setExpectedException ('DomainException ' );
345
+ } else {
346
+ $ this ->expectException ('DomainException ' );
347
+ }
280
348
$ pkey = openssl_pkey_new ();
281
349
$ msg = JWT ::encode ('abc ' , $ pkey , 'RS256 ' );
282
350
self ::$ opensslVerifyReturnValue = -1 ;
0 commit comments