From 098a96ded5b03bbc5c920831e71d0de0cf84cd6c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 30 Jun 2021 12:27:58 +0200 Subject: [PATCH] fix deprecated usage of phpunit annotations Signed-off-by: Arthur Schiwon --- tests/unit/Controller/SAMLControllerTest.php | 9 ++++---- .../Middleware/OnlyLoggedInMiddlewareTest.php | 21 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/unit/Controller/SAMLControllerTest.php b/tests/unit/Controller/SAMLControllerTest.php index f1d878d..c9af16f 100644 --- a/tests/unit/Controller/SAMLControllerTest.php +++ b/tests/unit/Controller/SAMLControllerTest.php @@ -21,6 +21,7 @@ namespace OCA\User_SAML\Tests\Controller; +use Exception; use OCA\User_SAML\Controller\SAMLController; use OCA\User_SAML\Exceptions\NoUserFoundException; use OCA\User_SAML\SAMLSettings; @@ -114,16 +115,16 @@ class SAMLControllerTest extends TestCase { } - /** - * @expectedExceptionMessage Type of "UnknownValue" is not supported for user_saml - * @expectedException \Exception - */ public function testLoginWithInvalidAppValue() { $this->config ->expects($this->once()) ->method('getAppValue') ->with('user_saml', 'type') ->willReturn('UnknownValue'); + + $this->expectException(Exception::class); + $this->expectExceptionMessage('Type of "UnknownValue" is not supported for user_saml'); + $this->samlController->login(1); } diff --git a/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php b/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php index a902fcc..9927cd9 100644 --- a/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php +++ b/tests/unit/Middleware/OnlyLoggedInMiddlewareTest.php @@ -21,6 +21,7 @@ namespace OCA\User_SAML\Tests\Middleware; +use Exception; use OCA\User_SAML\Middleware\OnlyLoggedInMiddleware; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; @@ -79,10 +80,6 @@ class OnlyLoggedInMiddlewareTest extends \Test\TestCase { $this->onlyLoggedInMiddleware->beforeController($this->createMock(Controller::class), 'bar'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage User is already logged-in - */ public function testBeforeControllerWithAnnotationAndLoggedIn() { $this->reflector ->expects($this->once()) @@ -94,15 +91,19 @@ class OnlyLoggedInMiddlewareTest extends \Test\TestCase { ->method('isLoggedIn') ->willReturn(true); + $this->expectException(Exception::class); + $this->expectExceptionMessage('User is already logged-in'); + $this->onlyLoggedInMiddleware->beforeController($this->createMock(Controller::class), 'bar'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage My Exception - */ public function testAfterExceptionWithNormalException() { - $exception = new \Exception('My Exception'); + $exceptionMsg = 'My Exception'; + $exception = new Exception($exceptionMsg); + + $this->expectException(Exception::class); + $this->expectExceptionMessage($exceptionMsg); + $this->onlyLoggedInMiddleware->afterException($this->createMock(Controller::class), 'bar', $exception); } @@ -113,7 +114,7 @@ class OnlyLoggedInMiddlewareTest extends \Test\TestCase { ->with('/') ->willReturn($homeUrl); - $exception = new \Exception('User is already logged-in'); + $exception = new Exception('User is already logged-in'); $expected = new RedirectResponse($homeUrl); $this->assertEquals($expected, $this->onlyLoggedInMiddleware->afterException($this->createMock(Controller::class), 'bar', $exception)); }