Skip to content

Commit 118d35f

Browse files
committed
test: fix tests that depends on table state
1 parent 7a21c49 commit 118d35f

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

tests/_support/MigrationTestMigrations/Database/Migrations/2018-01-24-102301_Some_migration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function up()
2121
'constraint' => 255,
2222
],
2323
]);
24-
$this->forge->createTable('foo', true);
24+
$this->forge->createTable('foo');
2525

2626
$this->db->table('foo')->insert([
2727
'key' => 'foobar',

tests/system/Commands/Database/MigrateStatusTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use CodeIgniter\CLI\CLI;
1515
use CodeIgniter\Test\CIUnitTestCase;
1616
use CodeIgniter\Test\StreamFilterTrait;
17+
use Config\Database;
1718

1819
/**
1920
* @group DatabaseLive
@@ -29,6 +30,9 @@ final class MigrateStatusTest extends CIUnitTestCase
2930

3031
protected function setUp(): void
3132
{
33+
$forge = Database::forge();
34+
$forge->dropTable('foo', true);
35+
3236
parent::setUp();
3337

3438
if (! is_file($this->migrationFileFrom)) {

tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ final class DatabaseTestCaseMigrationOnce1Test extends CIUnitTestCase
5656

5757
protected function setUp(): void
5858
{
59+
$forge = Database::forge();
60+
$forge->dropTable('foo', true);
61+
5962
$this->setUpMethods[] = 'setUpAddNamespace';
6063

6164
parent::setUp();

tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce2Test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use CodeIgniter\Test\CIUnitTestCase;
1515
use CodeIgniter\Test\DatabaseTestTrait;
16+
use Config\Database;
1617
use Config\Services;
1718

1819
/**
@@ -55,6 +56,9 @@ final class DatabaseTestCaseMigrationOnce2Test extends CIUnitTestCase
5556

5657
protected function setUp(): void
5758
{
59+
$forge = Database::forge();
60+
$forge->dropTable('foo', true);
61+
5862
$this->setUpMethods[] = 'setUpAddNamespace';
5963

6064
parent::setUp();

tests/system/Database/DatabaseTestCaseTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use CodeIgniter\Test\CIUnitTestCase;
1515
use CodeIgniter\Test\DatabaseTestTrait;
16+
use Config\Database;
1617
use Config\Services;
1718
use Tests\Support\Database\Seeds\AnotherSeeder;
1819
use Tests\Support\Database\Seeds\CITestSeeder;
@@ -60,6 +61,9 @@ final class DatabaseTestCaseTest extends CIUnitTestCase
6061

6162
protected function setUp(): void
6263
{
64+
$forge = Database::forge();
65+
$forge->dropTable('foo', true);
66+
6367
$this->setUpMethods[] = 'setUpAddNamespace';
6468

6569
parent::setUp();

tests/system/Database/Migrations/MigrationRunnerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ public function testLatestSuccess()
349349

350350
public function testRegressSuccess()
351351
{
352+
$forge = Database::forge();
353+
$forge->dropTable('foo', true);
354+
352355
$runner = new MigrationRunner($this->config);
353356
$runner->setSilent(false)
354357
->setNamespace('Tests\Support\MigrationTestMigrations')
@@ -368,6 +371,9 @@ public function testRegressSuccess()
368371

369372
public function testLatestTriggersEvent()
370373
{
374+
$forge = Database::forge();
375+
$forge->dropTable('foo', true);
376+
371377
$runner = new MigrationRunner($this->config);
372378
$runner->setSilent(false)
373379
->setNamespace('Tests\Support\MigrationTestMigrations');
@@ -387,6 +393,9 @@ public function testLatestTriggersEvent()
387393

388394
public function testRegressTriggersEvent()
389395
{
396+
$forge = Database::forge();
397+
$forge->dropTable('foo', true);
398+
390399
$runner = new MigrationRunner($this->config);
391400
$runner->setSilent(false)
392401
->setNamespace('Tests\Support\MigrationTestMigrations');

0 commit comments

Comments
 (0)