Skip to content

Commit d78dc89

Browse files
committed
test: address review feedbacks
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 87e7924 commit d78dc89

6 files changed

Lines changed: 22 additions & 39 deletions

File tree

system/Database/BaseConnection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,11 +1684,9 @@ protected function getDriverFunctionPrefix(): string
16841684
public function listTables(bool $constrainByPrefix = false)
16851685
{
16861686
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) {
1687-
$tables = $constrainByPrefix
1687+
return $constrainByPrefix
16881688
? preg_grep("/^{$this->DBPrefix}/", $this->dataCache['table_names'])
16891689
: $this->dataCache['table_names'];
1690-
1691-
return array_values($tables);
16921690
}
16931691

16941692
$sql = $this->_listTables($constrainByPrefix);

tests/system/Commands/Database/MigrateStatusTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ public function testMigrateWithWithTwoNamespaces(): void
8383

8484
private function assertMigrationStatusHasBothNamespaceMigrations(): void
8585
{
86-
$result = str_replace(PHP_EOL, "\n", $this->getStreamFilterBuffer());
86+
$result = str_replace(PHP_EOL, "\n", $this->getStreamFilterBuffer());
87+
$theadPattern = '/^\|[[:space:]]+Namespace[[:space:]]+\|[[:space:]]+Version[[:space:]]+\|[[:space:]]+Filename[[:space:]]+\|[[:space:]]+Group[[:space:]]+\|[[:space:]]+Migrated On[[:space:]]+\|[[:space:]]+Batch[[:space:]]+\|$/m';
8788

89+
$this->assertMatchesRegularExpression($theadPattern, $result);
8890
$this->assertStringContainsString($this->migrationNamespace, $result);
8991
$this->assertStringContainsString('2018-01-24-102301', $result);
9092
$this->assertStringContainsString('Some_migration', $result);

tests/system/Commands/Database/ShowTableInfoMockIOTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ protected function setUp(): void
3434
{
3535
parent::setUp();
3636

37+
$this->db->resetDataCache();
38+
3739
CLI::reset();
3840

3941
putenv('NO_COLOR=1');

tests/system/Commands/Database/ShowTableInfoTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ protected function setUp(): void
3535
{
3636
parent::setUp();
3737

38+
$this->db->resetDataCache();
39+
3840
putenv('NO_COLOR=1');
3941
CLI::init();
4042
}

tests/system/Commands/MigrationIntegrationTest.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,19 @@ public function testMigrationWithRollbackHasSameNameFormat(): void
6868

6969
private function dropTestTables(): void
7070
{
71-
$forge = Database::forge();
72-
73-
foreach ([
74-
'user',
75-
'job',
76-
'misc',
77-
'team_members',
78-
'type_test',
79-
'empty',
80-
'secondary',
81-
'stringifypkey',
82-
'without_auto_increment',
83-
'ip_table',
84-
'ci_sessions',
85-
'migrations_lock',
86-
] as $table) {
71+
$db = Database::connect();
72+
$forge = Database::forge();
73+
$tables = $db->listTables();
74+
75+
if ($tables === false) {
76+
return;
77+
}
78+
79+
foreach ($tables as $table) {
80+
if ($table === $db->DBPrefix . 'migrations') {
81+
continue;
82+
}
83+
8784
$forge->dropTable($table, true);
8885
}
8986
}

tests/system/Database/Live/MetadataTest.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function dropExtraneousTable(): void
7878
$oldPrefix = $this->db->getPrefix();
7979
$this->db->setPrefix('tmp_');
8080

81-
Database::forge($this->DBGroup)->dropTable('widgets', true);
81+
Database::forge($this->DBGroup)->dropTable('widgets');
8282

8383
$this->db->setPrefix($oldPrefix);
8484
}
@@ -139,22 +139,4 @@ public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtrane
139139
$this->dropExtraneousTable();
140140
}
141141
}
142-
143-
public function testListTablesReturnsListAfterCachedTableIsDropped(): void
144-
{
145-
try {
146-
$this->createExtraneousTable();
147-
148-
$tables = $this->db->listTables();
149-
$this->assertSame(array_values($tables), $tables);
150-
151-
$this->dropExtraneousTable();
152-
153-
$tables = $this->db->listTables();
154-
$this->assertSame(array_values($tables), $tables);
155-
$this->assertNotContains('tmp_widgets', $tables);
156-
} finally {
157-
$this->dropExtraneousTable();
158-
}
159-
}
160142
}

0 commit comments

Comments
 (0)