From b14da91a98f4cfef5fe3041584c8e935a7e8a93a Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 19 May 2020 23:12:08 +0200 Subject: [PATCH] Run integration tests in a transaction --- framework/core/tests/integration/TestCase.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/framework/core/tests/integration/TestCase.php b/framework/core/tests/integration/TestCase.php index 16a65f07e..916b1c06f 100644 --- a/framework/core/tests/integration/TestCase.php +++ b/framework/core/tests/integration/TestCase.php @@ -23,6 +23,20 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { use BuildsHttpRequests; + protected function setUp(): void + { + parent::setUp(); + + $this->database()->beginTransaction(); + } + + protected function tearDown(): void + { + parent::tearDown(); + + $this->database()->rollBack(); + } + /** * @var \Flarum\Foundation\InstalledApp */ @@ -94,13 +108,6 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase // We temporarily disable foreign key checks to simplify this process. $this->database()->getSchemaBuilder()->disableForeignKeyConstraints(); - // First, truncate all referenced tables so that they are empty. - foreach (array_keys($tableData) as $table) { - if ($table !== 'settings') { - $this->database()->table($table)->truncate(); - } - } - // Then, insert all rows required for this test case. foreach ($tableData as $table => $rows) { foreach ($rows as $row) {