mirror of
https://github.com/flarum/framework.git
synced 2025-03-10 04:05:30 +08:00
Run integration tests in a transaction
This commit is contained in:
parent
fb7ffc2351
commit
b14da91a98
@ -23,6 +23,20 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
|||||||
{
|
{
|
||||||
use BuildsHttpRequests;
|
use BuildsHttpRequests;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->database()->beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
$this->database()->rollBack();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Flarum\Foundation\InstalledApp
|
* @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.
|
// We temporarily disable foreign key checks to simplify this process.
|
||||||
$this->database()->getSchemaBuilder()->disableForeignKeyConstraints();
|
$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.
|
// Then, insert all rows required for this test case.
|
||||||
foreach ($tableData as $table => $rows) {
|
foreach ($tableData as $table => $rows) {
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user