1
0
mirror of https://github.com/flarum/core.git synced 2025-01-17 22:29:15 +01:00

Run integration tests in a transaction

This commit is contained in:
Franz Liedke 2020-05-19 23:12:08 +02:00 committed by Alexander Skvortsov
parent 94381dca62
commit 843a149b80

View File

@ -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) {