i'm kinda noobie in PHPUnit Testing and I need to cover multiple scenarios of a method. The method takes the rows of a table and make decisions based on it, so if I have 0 rows matching my query, it will execute some action, else, it will execute another.
I did the setup of DBUnit and everything is running, but the whole class is running the same getDataSet method so its running the same MySQLXMLDump.
For example:
testScenarioA -> Empty table.
testScenarioB -> Table has data.
I need to each test function on my class load a foo XML. How can I accomplish that?
So if you have a dataset in your Unit Test class, you could have the dataset return empty results and some data
public static function dataForTest() {
return [
'empty' => [getEmptyDataset()]
'results' => [getResults()]
];
}
Then in the function used for the tests use that with your dataset
/**
* @dataProvider dataForTest
*/
public function testSyncUser($dataTypes) {
foreach ($dataTypes as $dataType) {
// Run tests
}
}
Alternatively you could create a helper class to use alongside your unit tests to get data for the tests on the fly. PHPUnit generates all the data sets prior to instantiation of the Test Unit class so sometimes this can be a useful approach.