diff --git a/php-packages/testing/tests/integration/TestCase.php b/php-packages/testing/tests/integration/TestCase.php index 916b1c06f..5c8c5526c 100644 --- a/php-packages/testing/tests/integration/TestCase.php +++ b/php-packages/testing/tests/integration/TestCase.php @@ -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(