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