PHP Master: Write Cutting-edge Code php unit db testing
Database Testing - Assertions p.269
In code below one table from dataset… the other table from where came to get compared together?
class My_DaoTest extends PHPUnit_Extensions_Database_TestCase
{
private $dao;
// getConnection() and getDataSet() implementations from earlier➥
go here
protected function setUp()
{
$this->dao = new My_Dao;
// any other required setup – connecting to the database, etc.
}
public function testDoStuff()
{
$this->dao->doStuff();
// asserting table row count
$expected_row_count = 2;
$actual_row_count = $this->getConnection()->getRowCount
➥
('table_name');
$this->assertEquals($expected_row_count, $actual_row_count);
// asserting table / query result set equality
$expected_table = $this->createMySQLXMLDataSet
➥
('/path/to/expected_table.xml')
->getTable('table_name');
$actual_table = $this->getConnection()->createQueryTable➥
('table_name',
'SELECT * FROM table_name WHERE ...');
$this->assertTablesEqual($expected_table, $actual_table);
}
}