From 1ad510b61da47dd72c9bb4cb12a70ed75c45c4ea Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 12 Apr 2022 11:24:26 +0900 Subject: [PATCH] test: fix MigrationRunnerTest --- .../Database/Migrations/MigrationRunnerTest.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/system/Database/Migrations/MigrationRunnerTest.php b/tests/system/Database/Migrations/MigrationRunnerTest.php index e97e4e38e5..774137bc0f 100644 --- a/tests/system/Database/Migrations/MigrationRunnerTest.php +++ b/tests/system/Database/Migrations/MigrationRunnerTest.php @@ -33,6 +33,12 @@ final class MigrationRunnerTest extends CIUnitTestCase use DatabaseTestTrait; protected $refresh = true; + + // Do not migrate automatically, because we test migrations. + protected $migrate = false; + + // Use specific migration files for this test case. + protected $namespace = 'Tests\Support\MigrationTestMigrations'; protected $root; protected $start; protected $config; @@ -62,6 +68,8 @@ final class MigrationRunnerTest extends CIUnitTestCase { parent::tearDown(); + // To delete data with `$this->regressDatabase()`, set it true. + $this->migrate = true; $this->regressDatabase(); } @@ -342,10 +350,11 @@ final class MigrationRunnerTest extends CIUnitTestCase { $runner = new MigrationRunner($this->config); $runner->setSilent(false) - ->setNamespace('Tests\Support\MigrationTestMigrations') - ->clearHistory(); + ->setNamespace('Tests\Support\MigrationTestMigrations'); $result = null; + + Events::removeAllListeners(); Events::on('migrate', static function ($arg) use (&$result) { $result = $arg; }); @@ -360,10 +369,10 @@ final class MigrationRunnerTest extends CIUnitTestCase { $runner = new MigrationRunner($this->config); $runner->setSilent(false) - ->setNamespace('Tests\Support\MigrationTestMigrations') - ->clearHistory(); + ->setNamespace('Tests\Support\MigrationTestMigrations'); $result = null; + Events::removeAllListeners(); Events::on('migrate', static function ($arg) use (&$result) { $result = $arg; });