如何使用PHPUnit测试多个mysql模式?

Par*_*ney 13 php mysql phpunit unit-testing

我想测试一个使用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');
}
Run Code Online (Sandbox Code Playgroud)

有没有办法以某种方式使用多个模式,所以我可以测试一个查询,如:

SELECT *
FROM   schema1.tableA
JOIN   schema2.tableB
USING  (id)
Run Code Online (Sandbox Code Playgroud)

编辑:要清楚,我试图解决的问题是,我只能弄清楚如何将架构设置文件传递到一个数据库.我想找到一种方法来说"在schema1中创建tables1.xml,在schema2中创建tables2.xml".对于每个测试,将填充并杀死不同xml文件中引用的表.

小智 3

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

define('schema1', 'schema1_prod');
define('schema2', 'schema2_prod');
Run Code Online (Sandbox Code Playgroud)

然后进行单元测试

define('schema1', 'unit_tests');
define('schema2', 'unit_tests');
Run Code Online (Sandbox Code Playgroud)

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