Skip to content

Commit

Permalink
truncateDatabase 支持自定义连接,分表分库写测试用例需要
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Mar 18, 2023
1 parent 8db97a1 commit e6448a4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Leevel/Kernel/Testing/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait Database
/**
* 清理数据表.
*/
protected function truncateDatabase(array $tables): void
protected function truncateDatabase(array $tables, ?string $connect = null): void
{
if (!$tables) {
return;
Expand All @@ -28,16 +28,22 @@ protected function truncateDatabase(array $tables): void
false
]
eot;
Db::table($table)->truncate();
Db::connect($connect)
->table($table)
->truncate()
;

$this->assertSame(
sprintf($sql, $table),
$this->varJson(
Db::getRealLastSql()
Db::connect($connect)->getRealLastSql()
)
);

Db::table($table)->truncate();
Db::connect($connect)
->table($table)
->truncate()
;
}
}
}

0 comments on commit e6448a4

Please sign in to comment.