From b1baca99f280570d0336b4d71ad1f9dca213a35b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 27 Sep 2020 14:07:08 +0200 Subject: Convert legacy PHPUnit @expected* to new ->expect* Converted automatically using https://github.com/ArthurHoaro/convert-legacy-phpunit-expect --- tests/api/ApiUtilsTest.php | 72 +++++++++++++------------- tests/api/controllers/links/DeleteLinkTest.php | 4 +- tests/api/controllers/links/GetLinkIdTest.php | 6 +-- tests/api/controllers/links/PutLinkTest.php | 6 +-- tests/api/controllers/tags/DeleteTagTest.php | 6 +-- tests/api/controllers/tags/GetTagNameTest.php | 6 +-- tests/api/controllers/tags/PutTagTest.php | 12 ++--- 7 files changed, 56 insertions(+), 56 deletions(-) (limited to 'tests/api') diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php index e8075a5d..96787014 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php @@ -66,143 +66,143 @@ class ApiUtilsTest extends \PHPUnit\Framework\TestCase /** * Test validateJwtToken() with a malformed JWT token. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformed() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = 'ABC.DEF'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with an empty JWT token. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformedEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = false; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token without header. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformedEmptyHeader() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = '.payload.signature'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token without payload - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Malformed JWT token */ public function testValidateJwtTokenMalformedEmptyPayload() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Malformed JWT token'); + $token = 'header..signature'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token with an empty signature. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT signature */ public function testValidateJwtTokenInvalidSignatureEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT signature'); + $token = 'header.payload.'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token with an invalid signature. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT signature */ public function testValidateJwtTokenInvalidSignature() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT signature'); + $token = 'header.payload.nope'; ApiUtils::validateJwtToken($token, 'foo'); } /** * Test validateJwtToken() with a JWT token with a signature generated with the wrong API secret. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT signature */ public function testValidateJwtTokenInvalidSignatureSecret() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT signature'); + ApiUtils::validateJwtToken(self::generateValidJwtToken('foo'), 'bar'); } /** * Test validateJwtToken() with a JWT token with a an invalid header (not JSON). - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT header */ public function testValidateJwtTokenInvalidHeader() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT header'); + $token = $this->generateCustomJwtToken('notJSON', '{"JSON":1}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with a JWT token with a an invalid payload (not JSON). - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT payload */ public function testValidateJwtTokenInvalidPayload() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT payload'); + $token = $this->generateCustomJwtToken('{"JSON":1}', 'notJSON', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with a JWT token without issued time. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT issued time */ public function testValidateJwtTokenInvalidTimeEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT issued time'); + $token = $this->generateCustomJwtToken('{"JSON":1}', '{"JSON":1}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with an expired JWT token. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT issued time */ public function testValidateJwtTokenInvalidTimeExpired() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT issued time'); + $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() - 600) . '}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } /** * Test validateJwtToken() with a JWT token issued in the future. - * - * @expectedException \Shaarli\Api\Exceptions\ApiAuthorizationException - * @expectedExceptionMessage Invalid JWT issued time */ public function testValidateJwtTokenInvalidTimeFuture() { + $this->expectException(\Shaarli\Api\Exceptions\ApiAuthorizationException::class); + $this->expectExceptionMessage('Invalid JWT issued time'); + $token = $this->generateCustomJwtToken('{"JSON":1}', '{"iat":' . (time() + 60) . '}', 'secret'); ApiUtils::validateJwtToken($token, 'secret'); } diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php index 10dfe8bc..bd8403cf 100644 --- a/tests/api/controllers/links/DeleteLinkTest.php +++ b/tests/api/controllers/links/DeleteLinkTest.php @@ -113,11 +113,11 @@ class DeleteLinkTest extends \PHPUnit\Framework\TestCase /** * Test DELETE link endpoint: reach not existing ID. - * - * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException */ public function testDeleteLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $id = -1; $this->assertFalse($this->bookmarkService->exists($id)); $env = Environment::mock([ diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php index ee42e259..3a3aaa7b 100644 --- a/tests/api/controllers/links/GetLinkIdTest.php +++ b/tests/api/controllers/links/GetLinkIdTest.php @@ -120,12 +120,12 @@ class GetLinkIdTest extends \PHPUnit\Framework\TestCase /** * Test basic getLink service: get non existent link => ApiLinkNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException - * @expectedExceptionMessage Link not found */ public function testGetLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $this->expectExceptionMessage('Link not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', ]); diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index f582a2b5..3d62a1b1 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php @@ -218,12 +218,12 @@ class PutLinkTest extends \PHPUnit\Framework\TestCase /** * Test link update on non existent link => ApiLinkNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException - * @expectedExceptionMessage Link not found */ public function testGetLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiLinkNotFoundException::class); + $this->expectExceptionMessage('Link not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'PUT', ]); diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index b0980572..0d991b85 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php @@ -150,12 +150,12 @@ class DeleteTagTest extends \PHPUnit\Framework\TestCase /** * Test DELETE tag endpoint: reach not existing tag. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testDeleteLink404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $tagName = 'nopenope'; $tags = $this->bookmarkService->bookmarksCountPerTag(); $this->assertFalse(isset($tags[$tagName])); diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php index f8ee10d9..a2fb89ab 100644 --- a/tests/api/controllers/tags/GetTagNameTest.php +++ b/tests/api/controllers/tags/GetTagNameTest.php @@ -117,12 +117,12 @@ class GetTagNameTest extends \PHPUnit\Framework\TestCase /** * Test basic getTag service: get non existent tag => ApiTagNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testGetTag404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'GET', ]); diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php index e0bc8663..0845dce1 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php @@ -159,12 +159,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase /** * Test tag update with an empty new tag name => ApiBadParametersException - * - * @expectedException Shaarli\Api\Exceptions\ApiBadParametersException - * @expectedExceptionMessage New tag name is required in the request body */ public function testPutTagEmpty() { + $this->expectException(\Shaarli\Api\Exceptions\ApiBadParametersException::class); + $this->expectExceptionMessage('New tag name is required in the request body'); + $tagName = 'gnu'; $newName = ''; @@ -194,12 +194,12 @@ class PutTagTest extends \PHPUnit\Framework\TestCase /** * Test tag update on non existent tag => ApiTagNotFoundException. - * - * @expectedException Shaarli\Api\Exceptions\ApiTagNotFoundException - * @expectedExceptionMessage Tag not found */ public function testPutTag404() { + $this->expectException(\Shaarli\Api\Exceptions\ApiTagNotFoundException::class); + $this->expectExceptionMessage('Tag not found'); + $env = Environment::mock([ 'REQUEST_METHOD' => 'PUT', ]); -- cgit v1.2.3