PHPUnit: Get rid of deprecated annotation

Refs #1795.
This commit is contained in:
Franz Liedke 2019-07-30 00:09:10 +02:00 committed by Daniël Klabbers
parent 42a7f2f586
commit 970c0f5604
7 changed files with 35 additions and 15 deletions

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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]);
}
}