vendor/codeages/biz-framework/src/Testing/DbTestHelper.php

(开头部分) 895B

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Codeages\Biz\Framework\Testing;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;

class DbTestHelper
{
    /**
     * @var Connection
     */
    protected $db;

    public function __construct($db)
    {
        if ($db instanceof Connection) {
            $this->db = $db;
        } elseif (is_array($db)) {
            $this->db = DriverManager::getConnection($db);
        }
    }

    /**
     * 清除所有表的数据,表名前缀为`migration`的表除外。
     */
    public function truncateAllTables()
    {
        $schema = $this->db->getSchemaManager();
        $tableNames = $schema->listTableNames();
        foreach ($tableNames as $tableName) {
            if (0 === \strpos($tableName, 'migration')) {
                continue;
            }
            $sql = "TRUNCATE {$tableName}";
            $this->db->exec($sql);
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。