gpt4 book ai didi

php - 如何使用 PHPUnit 跨多个 mysql 模式进行测试?

转载 作者:IT老高 更新时间:2023-10-29 00:12:39 26 4
gpt4 key购买 nike

我想测试一个使用 PHPUnit 的 PHPUnit_Extensions_Database_TestCase 类跨多个模式进行查询的过程。我已经翻阅了文档、SO 和源代码,但似乎我必须使用以下内容设置我的数据库:

protected function getConnection()
{
$this->pdo = new PDO('mysql:host=localhost;dbname=unit_test_schema', 'xxxx', 'yyyy');
return $this->createDefaultDBConnection($this->pdo, 'unit_test_schema');
}

protected function getDataSet()
{
return $this->createXMLDataSet(DB_SETUP_DIR.'/schema.xml');
}

有没有办法以某种方式使用多个架构,以便我可以测试如下查询:

SELECT *
FROM schema1.tableA
JOIN schema2.tableB
USING (id)

编辑: 明确地说,我要解决的问题是我只能弄清楚如何将架构设置文件传递到一个数据库。我想找到一种方法来表示“在 schema1 中创建 tables1.xml,在 schema2 中创建 tables2.xml”。在不同的 xml 文件中引用的表将在每次测试中被填充和终止。

最佳答案

我做过的一件事是为每个模式创建一个定义,然后在单元测试时覆盖该定义

define('schema1', 'schema1_prod');
define('schema2', 'schema2_prod');

然后进行单元测试

define('schema1', 'unit_tests');
define('schema2', 'unit_tests');

如果您在多个模式中有类似的表名,这仍然会中断,但如果您不这样做,它应该会有所帮助。

关于php - 如何使用 PHPUnit 跨多个 mysql 模式进行测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5888078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com