Skip to content

Commit a083e49

Browse files
committed
Update unit tests expectException
1 parent f091dc2 commit a083e49

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/JWTTest.php

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

3232
public function testMalformedUtf8StringsFail()
3333
{
34-
$this->setExpectedException('DomainException');
34+
$this->expectException('DomainException');
3535
JWT::encode(pack('c', 128), 'a');
3636
}
3737

3838
public function testMalformedJsonThrowsException()
3939
{
40-
$this->setExpectedException('DomainException');
40+
$this->expectException('DomainException');
4141
JWT::jsonDecode('this is not valid JSON string');
4242
}
4343

4444
public function testExpiredToken()
4545
{
46-
$this->setExpectedException('Firebase\JWT\ExpiredException');
46+
$this->expectException('Firebase\JWT\ExpiredException');
4747
$payload = array(
4848
"message" => "abc",
4949
"exp" => time() - 20); // time in the past
@@ -53,7 +53,7 @@ public function testExpiredToken()
5353

5454
public function testBeforeValidTokenWithNbf()
5555
{
56-
$this->setExpectedException('Firebase\JWT\BeforeValidException');
56+
$this->expectException('Firebase\JWT\BeforeValidException');
5757
$payload = array(
5858
"message" => "abc",
5959
"nbf" => time() + 20); // time in the future
@@ -63,7 +63,7 @@ public function testBeforeValidTokenWithNbf()
6363

6464
public function testBeforeValidTokenWithIat()
6565
{
66-
$this->setExpectedException('Firebase\JWT\BeforeValidException');
66+
$this->expectException('Firebase\JWT\BeforeValidException');
6767
$payload = array(
6868
"message" => "abc",
6969
"iat" => time() + 20); // time in the future
@@ -99,7 +99,7 @@ public function testExpiredTokenWithLeeway()
9999
$payload = array(
100100
"message" => "abc",
101101
"exp" => time() - 70); // time far in the past
102-
$this->setExpectedException('Firebase\JWT\ExpiredException');
102+
$this->expectException('Firebase\JWT\ExpiredException');
103103
$encoded = JWT::encode($payload, 'my_key');
104104
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
105105
$this->assertEquals($decoded->message, 'abc');
@@ -147,7 +147,7 @@ public function testInvalidTokenWithNbfLeeway()
147147
"message" => "abc",
148148
"nbf" => time() + 65); // not before too far in future
149149
$encoded = JWT::encode($payload, 'my_key');
150-
$this->setExpectedException('Firebase\JWT\BeforeValidException');
150+
$this->expectException('Firebase\JWT\BeforeValidException');
151151
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
152152
JWT::$leeway = 0;
153153
}
@@ -171,7 +171,7 @@ public function testInvalidTokenWithIatLeeway()
171171
"message" => "abc",
172172
"iat" => time() + 65); // issued too far in future
173173
$encoded = JWT::encode($payload, 'my_key');
174-
$this->setExpectedException('Firebase\JWT\BeforeValidException');
174+
$this->expectException('Firebase\JWT\BeforeValidException');
175175
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
176176
JWT::$leeway = 0;
177177
}
@@ -182,7 +182,7 @@ public function testInvalidToken()
182182
"message" => "abc",
183183
"exp" => time() + 20); // time in the future
184184
$encoded = JWT::encode($payload, 'my_key');
185-
$this->setExpectedException('Firebase\JWT\SignatureInvalidException');
185+
$this->expectException('Firebase\JWT\SignatureInvalidException');
186186
$decoded = JWT::decode($encoded, 'my_key2', array('HS256'));
187187
}
188188

@@ -192,7 +192,7 @@ public function testNullKeyFails()
192192
"message" => "abc",
193193
"exp" => time() + JWT::$leeway + 20); // time in the future
194194
$encoded = JWT::encode($payload, 'my_key');
195-
$this->setExpectedException('InvalidArgumentException');
195+
$this->expectException('InvalidArgumentException');
196196
$decoded = JWT::decode($encoded, null, array('HS256'));
197197
}
198198

@@ -202,7 +202,7 @@ public function testEmptyKeyFails()
202202
"message" => "abc",
203203
"exp" => time() + JWT::$leeway + 20); // time in the future
204204
$encoded = JWT::encode($payload, 'my_key');
205-
$this->setExpectedException('InvalidArgumentException');
205+
$this->expectException('InvalidArgumentException');
206206
$decoded = JWT::decode($encoded, '', array('HS256'));
207207
}
208208

@@ -237,21 +237,21 @@ public function testArrayAccessKIDChooser()
237237
public function testNoneAlgorithm()
238238
{
239239
$msg = JWT::encode('abc', 'my_key');
240-
$this->setExpectedException('UnexpectedValueException');
240+
$this->expectException('UnexpectedValueException');
241241
JWT::decode($msg, 'my_key', array('none'));
242242
}
243243

244244
public function testIncorrectAlgorithm()
245245
{
246246
$msg = JWT::encode('abc', 'my_key');
247-
$this->setExpectedException('UnexpectedValueException');
247+
$this->expectException('UnexpectedValueException');
248248
JWT::decode($msg, 'my_key', array('RS256'));
249249
}
250250

251251
public function testMissingAlgorithm()
252252
{
253253
$msg = JWT::encode('abc', 'my_key');
254-
$this->setExpectedException('UnexpectedValueException');
254+
$this->expectException('UnexpectedValueException');
255255
JWT::decode($msg, 'my_key');
256256
}
257257

@@ -263,20 +263,20 @@ public function testAdditionalHeaders()
263263

264264
public function testInvalidSegmentCount()
265265
{
266-
$this->setExpectedException('UnexpectedValueException');
266+
$this->expectException('UnexpectedValueException');
267267
JWT::decode('brokenheader.brokenbody', 'my_key', array('HS256'));
268268
}
269269

270270
public function testInvalidSignatureEncoding()
271271
{
272272
$msg = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwibmFtZSI6ImZvbyJ9.Q4Kee9E8o0Xfo4ADXvYA8t7dN_X_bU9K5w6tXuiSjlUxx";
273-
$this->setExpectedException('UnexpectedValueException');
273+
$this->expectException('UnexpectedValueException');
274274
JWT::decode($msg, 'secret', array('HS256'));
275275
}
276276

277277
public function testVerifyError()
278278
{
279-
$this->setExpectedException('DomainException');
279+
$this->expectException('DomainException');
280280
$pkey = openssl_pkey_new();
281281
$msg = JWT::encode('abc', $pkey, 'RS256');
282282
self::$opensslVerifyReturnValue = -1;

0 commit comments

Comments
 (0)