diff --git a/tests/integration/api/Auth/AuthenticateWithApiKeyTest.php b/tests/integration/api/Auth/AuthenticateWithApiKeyTest.php index 5ceb53044..4ee0101a0 100644 --- a/tests/integration/api/Auth/AuthenticateWithApiKeyTest.php +++ b/tests/integration/api/Auth/AuthenticateWithApiKeyTest.php @@ -15,6 +15,7 @@ use Flarum\Api\Client; use Flarum\Api\Controller\CreateGroupController; use Flarum\Tests\integration\RetrievesAuthorizedUsers; use Flarum\Tests\integration\TestCase; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\Guest; use Flarum\User\User; use Illuminate\Support\Str; @@ -55,7 +56,6 @@ class AuthenticateWithApiKeyTest extends TestCase /** * @test - * @expectedException \Flarum\User\Exception\PermissionDeniedException */ public function cannot_authorize_without_key() { @@ -63,6 +63,8 @@ class AuthenticateWithApiKeyTest extends TestCase $api = $this->app()->getContainer()->make(Client::class); $api->setErrorHandler(null); + $this->expectException(PermissionDeniedException::class); + $api->send(CreateGroupController::class, new Guest); } diff --git a/tests/integration/api/Controller/CreateDiscussionControllerTest.php b/tests/integration/api/Controller/CreateDiscussionControllerTest.php index 38c7ae60d..bd1e27f2e 100644 --- a/tests/integration/api/Controller/CreateDiscussionControllerTest.php +++ b/tests/integration/api/Controller/CreateDiscussionControllerTest.php @@ -13,6 +13,7 @@ use Flarum\Api\Controller\CreateDiscussionController; use Flarum\Discussion\Discussion; use Flarum\User\User; use Illuminate\Support\Arr; +use Illuminate\Validation\ValidationException; class CreateDiscussionControllerTest extends ApiControllerTestCase { @@ -63,8 +64,6 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Illuminate\Validation\ValidationException - * @expectedExceptionMessage The given data was invalid. */ public function cannot_create_discussion_without_content() { @@ -72,13 +71,14 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase $data = Arr::except($this->data, 'content'); + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('The given data was invalid.'); + $this->callWith($data); } /** * @test - * @expectedException \Illuminate\Validation\ValidationException - * @expectedExceptionMessage The given data was invalid. */ public function cannot_create_discussion_without_title() { @@ -86,6 +86,9 @@ class CreateDiscussionControllerTest extends ApiControllerTestCase $data = Arr::except($this->data, 'title'); + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('The given data was invalid.'); + $this->callWith($data); } } diff --git a/tests/integration/api/Controller/CreateGroupControllerTest.php b/tests/integration/api/Controller/CreateGroupControllerTest.php index 34076338e..0f8104e4f 100644 --- a/tests/integration/api/Controller/CreateGroupControllerTest.php +++ b/tests/integration/api/Controller/CreateGroupControllerTest.php @@ -11,9 +11,11 @@ namespace Flarum\Tests\integration\api\Controller; use Flarum\Api\Controller\CreateGroupController; use Flarum\Group\Group; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\User; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use Illuminate\Validation\ValidationException; class CreateGroupControllerTest extends ApiControllerTestCase { @@ -46,13 +48,14 @@ class CreateGroupControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Illuminate\Validation\ValidationException - * @expectedExceptionMessage The given data was invalid. */ public function admin_cannot_create_group_without_data() { $this->actor = User::find(1); + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('The given data was invalid.'); + $this->callWith(); } @@ -79,12 +82,13 @@ class CreateGroupControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Flarum\User\Exception\PermissionDeniedException */ public function unauthorized_user_cannot_create_group() { $this->actor = User::find(2); + $this->expectException(PermissionDeniedException::class); + $this->callWith($this->data); } } diff --git a/tests/integration/api/Controller/CreateUserControllerTest.php b/tests/integration/api/Controller/CreateUserControllerTest.php index d07406bcf..d47edf372 100644 --- a/tests/integration/api/Controller/CreateUserControllerTest.php +++ b/tests/integration/api/Controller/CreateUserControllerTest.php @@ -11,8 +11,10 @@ namespace Flarum\Tests\integration\api\Controller; use Flarum\Api\Controller\CreateUserController; use Flarum\Settings\SettingsRepositoryInterface; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\User; use Illuminate\Support\Arr; +use Illuminate\Validation\ValidationException; class CreateUserControllerTest extends ApiControllerTestCase { @@ -46,11 +48,12 @@ class CreateUserControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Illuminate\Validation\ValidationException - * @expectedExceptionMessage The given data was invalid. */ public function cannot_create_user_without_data() { + $this->expectException(ValidationException::class); + $this->expectExceptionMessage('The given data was invalid.'); + $this->callWith(); } @@ -94,7 +97,6 @@ class CreateUserControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Flarum\User\Exception\PermissionDeniedException */ public function disabling_sign_up_prevents_user_creation() { @@ -102,6 +104,8 @@ class CreateUserControllerTest extends ApiControllerTestCase $settings = app(SettingsRepositoryInterface::class); $settings->set('allow_sign_up', false); + $this->expectException(PermissionDeniedException::class); + try { $this->callWith($this->data); } finally { diff --git a/tests/integration/api/Controller/ListNotificationsControllerTest.php b/tests/integration/api/Controller/ListNotificationsControllerTest.php index fffe1bb22..fefe8009f 100644 --- a/tests/integration/api/Controller/ListNotificationsControllerTest.php +++ b/tests/integration/api/Controller/ListNotificationsControllerTest.php @@ -10,6 +10,7 @@ namespace Flarum\Tests\integration\api\Controller; use Flarum\Api\Controller\ListNotificationsController; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\User; class ListNotificationsControllerTest extends ApiControllerTestCase @@ -29,10 +30,11 @@ class ListNotificationsControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Flarum\User\Exception\PermissionDeniedException */ public function disallows_index_for_guest() { + $this->expectException(PermissionDeniedException::class); + $this->callWith(); } diff --git a/tests/integration/api/Controller/ListUsersControllerTest.php b/tests/integration/api/Controller/ListUsersControllerTest.php index 2cba46f77..a3f74e518 100644 --- a/tests/integration/api/Controller/ListUsersControllerTest.php +++ b/tests/integration/api/Controller/ListUsersControllerTest.php @@ -10,6 +10,7 @@ namespace Flarum\Tests\integration\api\Controller; use Flarum\Api\Controller\ListUsersController; +use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\User; class ListUsersControllerTest extends ApiControllerTestCase @@ -35,10 +36,11 @@ class ListUsersControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Flarum\User\Exception\PermissionDeniedException */ public function disallows_index_for_guest() { + $this->expectException(PermissionDeniedException::class); + $this->callWith(); } diff --git a/tests/integration/api/Controller/ShowDiscussionControllerTest.php b/tests/integration/api/Controller/ShowDiscussionControllerTest.php index a7ebf8b43..4b9f579b6 100644 --- a/tests/integration/api/Controller/ShowDiscussionControllerTest.php +++ b/tests/integration/api/Controller/ShowDiscussionControllerTest.php @@ -13,6 +13,7 @@ use Carbon\Carbon; use Flarum\Api\Controller\ShowDiscussionController; use Flarum\Discussion\Discussion; use Flarum\User\User; +use Illuminate\Database\Eloquent\ModelNotFoundException; class ShowDiscussionControllerTest extends ApiControllerTestCase { @@ -67,10 +68,11 @@ class ShowDiscussionControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException */ public function guest_cannot_see_empty_discussion() { + $this->expectException(ModelNotFoundException::class); + $response = $this->callWith([], ['id' => 1]); $this->assertEquals(200, $response->getStatusCode()); @@ -88,10 +90,11 @@ class ShowDiscussionControllerTest extends ApiControllerTestCase /** * @test - * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException */ public function guests_cannot_see_private_discussion() { + $this->expectException(ModelNotFoundException::class); + $this->callWith([], ['id' => 3]); } }