From ae280016e770d88cca3cac6a06b76abb1499236f Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Wed, 6 Jan 2021 22:34:32 -0500 Subject: [PATCH] Tests: remove prepDb workaround Previously, the `prepareDatabase` method would directly modify the database, booting the app in the process. This would prevent any extenders from being applied, since `->extend()` has no effect once the app is booted. Since the new implementation of `prepareDatabase` simply registers seed data to be applied during app boot, the workaround of sticking this seed data into `prepDb` is no longer necessary, and seed data common to all test cases in a class can be provided in `setUp`. When needed, app boot is explicitly triggered in individual test cases by calling `$this->app()`. --- .../extenders/ApiControllerTest.php | 65 ++----------------- .../extenders/ApiSerializerTest.php | 21 ++---- tests/integration/extenders/CsrfTest.php | 2 - tests/integration/extenders/ModelTest.php | 38 ++++++----- tests/integration/extenders/ModelUrlTest.php | 11 ++-- .../extenders/ModelVisibilityTest.php | 21 +++--- tests/integration/extenders/PolicyTest.php | 31 ++++----- tests/integration/extenders/SettingsTest.php | 19 ++---- .../integration/extenders/ThrottleApiTest.php | 15 ++--- tests/integration/extenders/UserTest.php | 31 +++++---- 10 files changed, 96 insertions(+), 158 deletions(-) diff --git a/tests/integration/extenders/ApiControllerTest.php b/tests/integration/extenders/ApiControllerTest.php index 349622aff..2c6be92ff 100644 --- a/tests/integration/extenders/ApiControllerTest.php +++ b/tests/integration/extenders/ApiControllerTest.php @@ -31,8 +31,13 @@ class ApiControllerTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser() @@ -43,8 +48,6 @@ class ApiControllerTest extends TestCase ['id' => 3, 'title' => 'Custom Discussion Title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 0, 'comment_count' => 1, 'is_private' => 0], ], ]); - - $this->app(); } /** @@ -59,8 +62,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -82,8 +83,6 @@ class ApiControllerTest extends TestCase ->prepareDataForSerialization(CustomPrepareDataSerializationInvokableClass::class) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -110,8 +109,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -136,8 +133,6 @@ class ApiControllerTest extends TestCase ->prepareDataForSerialization(CustomInvokableClassArgsReference::class) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -163,8 +158,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -194,8 +187,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -221,8 +212,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -252,8 +241,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -270,8 +257,6 @@ class ApiControllerTest extends TestCase */ public function custom_serializer_doesnt_work_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -293,8 +278,6 @@ class ApiControllerTest extends TestCase ->setSerializer(CustomDiscussionSerializer::class) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions/1', [ 'authenticatedAs' => 1, @@ -315,8 +298,6 @@ class ApiControllerTest extends TestCase (new Extend\ApiController(ShowPostController::class)) ->setSerializer(CustomPostSerializer::class, CustomApiControllerInvokableClass::class) ); - - $this->prepDb(); $this->prepareDatabase([ 'posts' => [ ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'comment', 'content' => '

foo bar

'], @@ -329,8 +310,6 @@ class ApiControllerTest extends TestCase ]) ); - echo $response->getBody(); - $payload = json_decode($response->getBody(), true); $this->assertArrayHasKey('customSerializer', $payload['data']['attributes']); @@ -348,8 +327,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -366,8 +343,6 @@ class ApiControllerTest extends TestCase */ public function custom_relationship_not_included_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -394,8 +369,6 @@ class ApiControllerTest extends TestCase ->addInclude('customApiControllerRelation') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -421,8 +394,6 @@ class ApiControllerTest extends TestCase ->addOptionalInclude('customApiControllerRelation2') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -441,8 +412,6 @@ class ApiControllerTest extends TestCase */ public function custom_relationship_included_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -464,8 +433,6 @@ class ApiControllerTest extends TestCase ->removeInclude('groups') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -492,8 +459,6 @@ class ApiControllerTest extends TestCase ->removeOptionalInclude('customApiControllerRelation2') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, @@ -510,8 +475,6 @@ class ApiControllerTest extends TestCase */ public function custom_limit_doesnt_work_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -533,8 +496,6 @@ class ApiControllerTest extends TestCase ->setLimit(1) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -556,8 +517,6 @@ class ApiControllerTest extends TestCase ->setMaxLimit(1) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -576,8 +535,6 @@ class ApiControllerTest extends TestCase */ public function custom_sort_field_doesnt_exist_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -601,8 +558,6 @@ class ApiControllerTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -624,8 +579,6 @@ class ApiControllerTest extends TestCase ->addSortField('userId') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -645,8 +598,6 @@ class ApiControllerTest extends TestCase */ public function custom_sort_field_exists_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -668,8 +619,6 @@ class ApiControllerTest extends TestCase ->removeSortField('createdAt') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, @@ -692,8 +641,6 @@ class ApiControllerTest extends TestCase ->setSort(['userId' => 'desc']) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api/discussions', [ 'authenticatedAs' => 1, diff --git a/tests/integration/extenders/ApiSerializerTest.php b/tests/integration/extenders/ApiSerializerTest.php index ad1e3274f..8548d453c 100644 --- a/tests/integration/extenders/ApiSerializerTest.php +++ b/tests/integration/extenders/ApiSerializerTest.php @@ -27,8 +27,13 @@ class ApiSerializerTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser() @@ -42,8 +47,6 @@ class ApiSerializerTest extends TestCase ['id' => 1, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => '

can i haz relationz?

'], ], ]); - - $this->app(); } /** @@ -329,8 +332,6 @@ class ApiSerializerTest extends TestCase ->hasMany('customSerializerRelation', DiscussionSerializer::class) ); - $this->prepDb(); - $request = $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, ]); @@ -356,8 +357,6 @@ class ApiSerializerTest extends TestCase ->hasOne('customSerializerRelation', DiscussionSerializer::class) ); - $this->prepDb(); - $request = $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, ]); @@ -385,8 +384,6 @@ class ApiSerializerTest extends TestCase }) ); - $this->prepDb(); - $request = $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, ]); @@ -412,8 +409,6 @@ class ApiSerializerTest extends TestCase ->relationship('customSerializerRelation', CustomRelationshipInvokableClass::class) ); - $this->prepDb(); - $request = $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, ]); @@ -439,8 +434,6 @@ class ApiSerializerTest extends TestCase ->hasMany('anotherCustomRelation', DiscussionSerializer::class) ); - $this->prepDb(); - $request = $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, ]); @@ -472,8 +465,6 @@ class ApiSerializerTest extends TestCase }) ); - $this->prepDb(); - $request = $this->request('GET', '/api/users/2', [ 'authenticatedAs' => 1, ]); diff --git a/tests/integration/extenders/CsrfTest.php b/tests/integration/extenders/CsrfTest.php index db841e0a0..0b6f8cec0 100644 --- a/tests/integration/extenders/CsrfTest.php +++ b/tests/integration/extenders/CsrfTest.php @@ -79,8 +79,6 @@ class CsrfTest extends TestCase ->exemptRoute('users.create') ); - $this->prepDb(); - $response = $this->send( $this->request('POST', '/api/users', [ 'json' => [ diff --git a/tests/integration/extenders/ModelTest.php b/tests/integration/extenders/ModelTest.php index f4e219975..f40c71d90 100644 --- a/tests/integration/extenders/ModelTest.php +++ b/tests/integration/extenders/ModelTest.php @@ -25,23 +25,23 @@ class ModelTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser(), ], ]); - - $this->app(); } protected function prepPostsHierarchy() { $this->prepareDatabase([ - 'users' => [ - $this->normalUser(), - ], 'discussions' => [ ['id' => 1, 'title' => 'Discussion with post', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => 1, 'comment_count' => 1, 'is_private' => 0], ], @@ -49,8 +49,6 @@ class ModelTest extends TestCase ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'type' => 'discussionRenamed', 'content' => '

can i haz relationz?

'], ], ]); - - $this->app(); } /** @@ -58,7 +56,7 @@ class ModelTest extends TestCase */ public function custom_relationship_does_not_exist_by_default() { - $this->prepDB(); + $this->app(); $user = User::find(1); @@ -76,7 +74,7 @@ class ModelTest extends TestCase ->hasOne('customRelation', Discussion::class, 'user_id') ); - $this->prepDB(); + $this->app(); $user = User::find(1); @@ -93,7 +91,7 @@ class ModelTest extends TestCase ->hasMany('customRelation', Discussion::class, 'user_id') ); - $this->prepDB(); + $this->app(); $user = User::find(1); @@ -110,7 +108,7 @@ class ModelTest extends TestCase ->belongsTo('customRelation', Discussion::class, 'user_id') ); - $this->prepDB(); + $this->app(); $user = User::find(1); @@ -129,7 +127,7 @@ class ModelTest extends TestCase }) ); - $this->prepDB(); + $this->app(); $user = User::find(1); @@ -146,7 +144,7 @@ class ModelTest extends TestCase ->relationship('customRelation', CustomRelationClass::class) ); - $this->prepDB(); + $this->app(); $user = User::find(1); @@ -170,7 +168,8 @@ class ModelTest extends TestCase ['id' => 1, 'title' => __CLASS__, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'first_post_id' => 1, 'comment_count' => 1] ] ]); - $this->prepDB(); + + $this->app(); $user = User::find(1); @@ -190,6 +189,8 @@ class ModelTest extends TestCase $this->prepPostsHierarchy(); + $this->app(); + $post = CommentPost::find(1); $this->assertInstanceOf(Discussion::class, $post->ancestor); @@ -210,6 +211,8 @@ class ModelTest extends TestCase $this->prepPostsHierarchy(); + $this->app(); + $post = DiscussionRenamedPost::find(1); $this->assertInstanceOf(Discussion::class, $post->ancestor); @@ -229,6 +232,9 @@ class ModelTest extends TestCase ); $this->prepPostsHierarchy(); + + $this->app(); + $post = DiscussionRenamedPost::find(1); $this->assertInstanceOf(User::class, $post->ancestor); @@ -247,7 +253,7 @@ class ModelTest extends TestCase }) ); - $this->prepDB(); + $this->app(); $group = Group::find(1); diff --git a/tests/integration/extenders/ModelUrlTest.php b/tests/integration/extenders/ModelUrlTest.php index 44abd1ef6..ab3eef49b 100644 --- a/tests/integration/extenders/ModelUrlTest.php +++ b/tests/integration/extenders/ModelUrlTest.php @@ -21,8 +21,13 @@ class ModelUrlTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $userClass = User::class; $this->prepareDatabase([ 'users' => [ @@ -39,8 +44,6 @@ class ModelUrlTest extends TestCase */ public function uses_default_driver_by_default() { - $this->prepDb(); - $slugManager = $this->app()->getContainer()->make(SlugManager::class); $testUser = User::find(1); @@ -56,8 +59,6 @@ class ModelUrlTest extends TestCase { $this->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class)); - $this->prepDb(); - $slugManager = $this->app()->getContainer()->make(SlugManager::class); $testUser = User::find(1); diff --git a/tests/integration/extenders/ModelVisibilityTest.php b/tests/integration/extenders/ModelVisibilityTest.php index d05c98fb7..25322167e 100644 --- a/tests/integration/extenders/ModelVisibilityTest.php +++ b/tests/integration/extenders/ModelVisibilityTest.php @@ -23,8 +23,13 @@ class ModelVisibilityTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'discussions' => [ ['id' => 1, 'title' => 'Empty discussion', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 2, 'first_post_id' => null, 'comment_count' => 0, 'is_private' => 0], @@ -39,8 +44,6 @@ class ModelVisibilityTest extends TestCase $this->normalUser(), ] ]); - - $this->app(); } /** @@ -48,7 +51,7 @@ class ModelVisibilityTest extends TestCase */ public function user_can_see_posts_by_default() { - $this->prepDb(); + $this->app(); $actor = User::find(2); @@ -69,7 +72,7 @@ class ModelVisibilityTest extends TestCase }, 'view') ); - $this->prepDb(); + $this->app(); $actor = User::find(2); @@ -90,7 +93,7 @@ class ModelVisibilityTest extends TestCase }, 'view') ); - $this->prepDb(); + $this->app(); $actor = User::find(2); @@ -115,7 +118,7 @@ class ModelVisibilityTest extends TestCase }, 'view') ); - $this->prepDb(); + $this->app(); $actor = User::find(2); @@ -140,7 +143,7 @@ class ModelVisibilityTest extends TestCase }, 'viewPrivate') ); - $this->prepDb(); + $this->app(); $actor = User::find(2); @@ -169,7 +172,7 @@ class ModelVisibilityTest extends TestCase }) ); - $this->prepDb(); + $this->app(); $actor = User::find(2); diff --git a/tests/integration/extenders/PolicyTest.php b/tests/integration/extenders/PolicyTest.php index 082af73e9..978d0fff9 100644 --- a/tests/integration/extenders/PolicyTest.php +++ b/tests/integration/extenders/PolicyTest.php @@ -28,8 +28,13 @@ class PolicyTest extends TestCase // Request body to hide discussions sent in tests. protected $hideQuery = ['authenticatedAs' => 2, 'json' => ['data' => ['attributes' => ['isHidden' => true]]]]; - private function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser(), @@ -41,8 +46,6 @@ class PolicyTest extends TestCase ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

a normal reply - too-obscure

'], ] ]); - - $this->app(); } /** @@ -50,8 +53,6 @@ class PolicyTest extends TestCase */ public function unrelated_user_cant_hide_discussion_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('PATCH', '/api/discussions/1', $this->hideQuery) ); @@ -69,8 +70,6 @@ class PolicyTest extends TestCase ->modelPolicy(Discussion::class, CustomPolicy::class) ); - $this->prepDb(); - $response = $this->send( $this->request('PATCH', '/api/discussions/1', $this->hideQuery) ); @@ -89,8 +88,6 @@ class PolicyTest extends TestCase ->modelPolicy(Discussion::class, CustomPolicy::class) ); - $this->prepDb(); - $response = $this->send( $this->request('PATCH', '/api/discussions/1', $this->hideQuery) ); @@ -110,8 +107,6 @@ class PolicyTest extends TestCase ->modelPolicy(Discussion::class, CustomPolicy::class) ); - $this->prepDb(); - $response = $this->send( $this->request('PATCH', '/api/discussions/1', $this->hideQuery) ); @@ -132,8 +127,6 @@ class PolicyTest extends TestCase ->modelPolicy(Discussion::class, ForceAllowHidePolicy::class) ); - $this->prepDb(); - $response = $this->send( $this->request('PATCH', '/api/discussions/1', $this->hideQuery) ); @@ -146,7 +139,7 @@ class PolicyTest extends TestCase */ public function regular_user_cant_start_discussions_by_default() { - $this->prepDb(); + $this->app(); $user = User::find(2); @@ -163,7 +156,7 @@ class PolicyTest extends TestCase ->globalPolicy(GlobalStartDiscussionPolicy::class) ); - $this->prepDb(); + $this->app(); $user = User::find(2); @@ -180,7 +173,7 @@ class PolicyTest extends TestCase ->globalPolicy(GlobalStartDiscussionPolicy::class) ); - $this->prepDb(); + $this->app(); $user = User::find(2); @@ -192,7 +185,7 @@ class PolicyTest extends TestCase */ public function unrelated_user_cant_hide_post_by_default() { - $this->prepDb(); + $this->app(); $user = User::find(2); @@ -207,7 +200,7 @@ class PolicyTest extends TestCase $this->extend( (new Extend\Policy)->modelPolicy(CommentPost::class, CommentPostChildClassPolicy::class) ); - $this->prepDb(); + $this->app(); $user = User::find(2); @@ -223,7 +216,7 @@ class PolicyTest extends TestCase (new Extend\Policy)->modelPolicy(Post::class, PostParentClassPolicy::class), (new Extend\Policy)->modelPolicy(CommentPost::class, CommentPostChildClassPolicy::class) ); - $this->prepDb(); + $this->app(); $user = User::find(2); diff --git a/tests/integration/extenders/SettingsTest.php b/tests/integration/extenders/SettingsTest.php index 77c41d70e..d279bfd27 100644 --- a/tests/integration/extenders/SettingsTest.php +++ b/tests/integration/extenders/SettingsTest.php @@ -17,8 +17,13 @@ class SettingsTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser() @@ -35,8 +40,6 @@ class SettingsTest extends TestCase */ public function custom_setting_isnt_serialized_by_default() { - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -58,8 +61,6 @@ class SettingsTest extends TestCase ->serializeToForum('customPrefix.customSetting', 'custom-prefix.custom_setting') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -84,8 +85,6 @@ class SettingsTest extends TestCase }) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -108,8 +107,6 @@ class SettingsTest extends TestCase ->serializeToForum('customPrefix.customSetting2', 'custom-prefix.custom_setting2', CustomInvokableClass::class) ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -132,8 +129,6 @@ class SettingsTest extends TestCase ->serializeToForum('customPrefix.noCustomSetting', 'custom-prefix.no_custom_setting', null, 'customDefault') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, @@ -158,8 +153,6 @@ class SettingsTest extends TestCase }, 'customDefault') ); - $this->prepDb(); - $response = $this->send( $this->request('GET', '/api', [ 'authenticatedAs' => 1, diff --git a/tests/integration/extenders/ThrottleApiTest.php b/tests/integration/extenders/ThrottleApiTest.php index 33a4853e7..b2e88798b 100644 --- a/tests/integration/extenders/ThrottleApiTest.php +++ b/tests/integration/extenders/ThrottleApiTest.php @@ -17,8 +17,13 @@ class ThrottleApiTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb(): void + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser(), @@ -31,8 +36,6 @@ class ThrottleApiTest extends TestCase */ public function list_discussions_not_restricted_by_default() { - $this->prepDb(); - $response = $this->send($this->request('GET', '/api/discussions', ['authenticatedAs' => 2])); $this->assertEquals(200, $response->getStatusCode()); @@ -49,8 +52,6 @@ class ThrottleApiTest extends TestCase } })); - $this->prepDb(); - $response = $this->send($this->request('GET', '/api/discussions', ['authenticatedAs' => 2])); $this->assertEquals(429, $response->getStatusCode()); @@ -74,10 +75,6 @@ class ThrottleApiTest extends TestCase }) ); - $this->prepDb(); - - $this->prepDb(); - $response = $this->send($this->request('GET', '/api/discussions', ['authenticatedAs' => 2])); $this->assertEquals(200, $response->getStatusCode()); diff --git a/tests/integration/extenders/UserTest.php b/tests/integration/extenders/UserTest.php index 02ce5f00e..497bc7f95 100644 --- a/tests/integration/extenders/UserTest.php +++ b/tests/integration/extenders/UserTest.php @@ -20,8 +20,13 @@ class UserTest extends TestCase { use RetrievesAuthorizedUsers; - protected function prepDb() + /** + * @inheritDoc + */ + protected function setUp(): void { + parent::setUp(); + $this->prepareDatabase([ 'users' => [ $this->normalUser(), @@ -30,8 +35,6 @@ class UserTest extends TestCase ['key' => 'display_name_driver', 'value' => 'custom'], ] ]); - - $this->app(); } protected function registerTestPreference() @@ -47,7 +50,7 @@ class UserTest extends TestCase */ public function username_display_name_driver_used_by_default() { - $this->prepDb(); + $this->app(); $user = User::find(1); @@ -64,7 +67,7 @@ class UserTest extends TestCase ->displayNameDriver('custom', CustomDisplayNameDriver::class) ); - $this->prepDb(); + $this->app(); $user = User::find(1); @@ -76,7 +79,8 @@ class UserTest extends TestCase */ public function user_has_permissions_for_expected_groups_if_no_processors_added() { - $this->prepDb(); + $this->app(); + $user = User::find(2); $this->assertContains('viewUserList', $user->getPermissions()); @@ -93,7 +97,8 @@ class UserTest extends TestCase }); })); - $this->prepDb(); + $this->app(); + $user = User::find(2); $this->assertNotContains('viewUserList', $user->getPermissions()); @@ -106,7 +111,8 @@ class UserTest extends TestCase { $this->extend((new Extend\User)->permissionGroups(CustomGroupProcessorClass::class)); - $this->prepDb(); + $this->app(); + $user = User::find(2); $this->assertNotContains('viewUserList', $user->getPermissions()); @@ -118,7 +124,8 @@ class UserTest extends TestCase public function can_add_user_preference() { $this->registerTestPreference(); - $this->prepDb(); + + $this->app(); /** @var User $user */ $user = User::find(2); @@ -131,7 +138,8 @@ class UserTest extends TestCase public function can_store_user_preference() { $this->registerTestPreference(); - $this->prepDb(); + + $this->app(); /** @var User $user */ $user = User::find(2); @@ -147,7 +155,8 @@ class UserTest extends TestCase public function storing_user_preference_modified_by_transformer() { $this->registerTestPreference(); - $this->prepDb(); + + $this->app(); /** @var User $user */ $user = User::find(2);