unit - testing php



How to test across multiple mysql schemas with PHPUnit? (1)

I would like to test a process that queries across multiple schemas using PHPUnit's PHPUnit_Extensions_Database_TestCase class. I've dug through the documentation, SO and the source code, but it seems like I have to set up my database using something like:

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');
}

Is there a way to somehow use more than one schema so I can test a query like:

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

EDIT: To be clear, the issue I'm trying to resolve is that I can only figure out how to pass schema setup files to one database. I'd like to find a way to say "create tables1.xml in schema1 and tables2.xml in schema2." The tables referenced in the different xml files would be filled-and-killed for each test.


One thing I've done is created a definition for each schema, then overrode the definition when unit testing

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

Then for unit testing

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

If you have like table names across multiple schemas this will still break, but it should help if you don't.





phpunit