I have finally gotten some time to do some long awaited work on PHPUnit. The first on my agenda was a small improvement to filtering. This was related to ticket #526. Essentially I added the ability to do both white list and black list filtering.
For instance, if you wanted to specify an include filter you can do the following:
//...
$filteredDataSet = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet);
$filteredDataSet->addIncludeTables(array('table1', 'table3'));
$filteredDataSet->setIncludeColumnsForTable('table1', array('column1', 'column2', 'column3', 'column4'));
$filteredDataSet->setIncludeColumnsForTable('table3', array('column9', 'column10', 'column11', 'column12'));
//...
?>
I have also deprecated passing the filter to the constructor. The reason for this is that I would like to begin adding a few more features to the filter and the current method of passing the parameters on the constructor would be unintuitive for these planned features. Basically I think it was a mistake for me to allow the passing of filter data on the constructor to begin with. I anticipate the current method working up to PHPUnit 4.0 but it will not be expanded on and will be removed either in PHPUnit 4 or in a release soon after that.
So, for exclude filters, instead of specifying them in the constructor, the new method will be:
//...
$filteredDataSet = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet);
$filteredDataSet->addExcludeTables(array('table2'));
$filteredDataSet->setExcludeColumnsForTable('table1', array('table1_id'));
$filteredDataSet->setExcludeColumnsForTable('table3', array('table3_id'));
//...
?>
While you can’t mix include and exclude filters for tables (wouldn’t make sense right now) you CAN do this for table columns of separate tables:
//...
$filteredDataSet = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet);
$filteredDataSet->addIncludeTables(array('table1', 'table3'));
$filteredDataSet->setExcludeColumnsForTable('table1', array('table1_id'));
$filteredDataSet->setIncludeColumnsForTable('table3', array('column9', 'column10', 'column11', 'column12'));
//...
?>
Some future features I plan on adding include, global column includes/excludes and wild cards. Anyhow, hope this is useful for someone.
Pingback: Testing datetimes with phpunit datasets - SitePoint Forums