mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 07:03:38 +08:00
Tests: Always start transaction before seeding
This commit is contained in:
parent
663f7a5d32
commit
6ca9191f42
@ -23,13 +23,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
use BuildsHttpRequests;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->database()->beginTransaction();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
@ -61,6 +54,10 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
$site->extendWith($this->extenders);
|
||||
|
||||
$this->app = $site->bootApp();
|
||||
|
||||
$this->database()->beginTransaction();
|
||||
|
||||
$this->populateDatabase();
|
||||
}
|
||||
|
||||
return $this->app;
|
||||
@ -103,13 +100,23 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
protected $databaseContent = [];
|
||||
|
||||
protected function prepareDatabase(array $tableData)
|
||||
{
|
||||
$this->databaseContent = array_merge_recursive(
|
||||
$this->databaseContent,
|
||||
$tableData
|
||||
);
|
||||
}
|
||||
|
||||
protected function populateDatabase()
|
||||
{
|
||||
// We temporarily disable foreign key checks to simplify this process.
|
||||
$this->database()->getSchemaBuilder()->disableForeignKeyConstraints();
|
||||
|
||||
// Then, insert all rows required for this test case.
|
||||
foreach ($tableData as $table => $rows) {
|
||||
foreach ($this->databaseContent as $table => $rows) {
|
||||
foreach ($rows as $row) {
|
||||
if ($table === 'settings') {
|
||||
$this->database()->table($table)->updateOrInsert(
|
||||
|
Loading…
x
Reference in New Issue
Block a user