Nested Data Provider with Dependency in PHPUnit 2


For the longest time there was no way to take advantage of both dependecies with the @depends tag and the @dataProvider. The reason you might need to do this is if you want to have a chain of tests that have dependencies in them where the first function uses a data provider to test multiple datasets. The only issue with this is that you cannot retrieve the results from a test which uses @dataProvider because PHPUnit runs the dataprovider function before it executes any tests. see Data Providers with Dependencies. What we are really searching for is a way to utilize dependency of one test on another between multiple tests for a single dataset. This allows us to have an @dataProvider with dependencies. The following is the solution. Let me know if you have any questions!

Josh Woodcock, PMI-ACP, Agile Coach


Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “Nested Data Provider with Dependency in PHPUnit