mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
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()`.
This commit is contained in:
@@ -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' => '<t><p>can i haz relationz?</p></t>'],
|
||||
],
|
||||
]);
|
||||
|
||||
$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);
|
||||
|
||||
|
Reference in New Issue
Block a user