This is a late answer, but it may be useful to some people, I think ...
You can accomplish this by calling the execute
IDatabaseOperation
method, which you can get from PHPUnit_Extensions_Database_Operation_Factory
. Basically you would use CLEAN_INSERT
or INSERT
.
As a second zerkms approach , you would name it at the beginning of every test that needs specific data. For instance:
public function testA() { PHPUnit_Extensions_Database_Operation_Factory::INSERT() ->execute($this->getConnection(), $this->createXMLDataSet(__DIR__.'/fixtureA.xml'));
However, the advantage of this solution is that the data set of the entire test case remains unchanged, therefore:
- Test methods remain independent of each other (whereas in the zerkms approach, if you remember to specify the data set in another testing method, it will reuse the data set from the previous (random?) Method, which changed the data set, which is quite ugly and very subject to errors IMHO). Here, any other test without such a call at the beginning will simply use the test case dataset, as usual.
- You can create a test data set on top of a common data set (test case) . If you use the
INSERT
operation (not CLEAN_INSERT
), it will insert test-specific rows after all rows from the shared dataset. You can also use the DELETE
operation to remove some unwanted rows from this shared dataset. - BTW, without calling
onSetUp()
, does this work, even if the work on setting up a test case has been changed.
source share