Tip #3 Shared Data Providers
Did you ever wonder, why you can specify the file name for expectations and fixtures, but for data providers you seem to be limited to the default “test name dot yaml”? The simple reason is, @dataProvider
is a native feature of PHPUnit and its parameter actually must be a method name.
So @dataProvider dataProvider
means, the method EcomDev_PHPUnit_Test_Case::dataProvider()
is used as data provider:
/** * Implements default data provider functionality, * returns array data loaded from Yaml file with the same name as test method * * @param string $testName * @return array */ public function dataProvider($testName) { return TestUtil::dataProvider(get_called_class(), $testName); }
But EcomDev_PHPUnit also has a way to specify the file name for the data provider explicitly, thus allows shared providers:
/** * @dataProvider dataProvider * @dataProviderFile customFileName.yaml */ public function testSomething($something)
One Reply to “EcomDev_PHPUnit Tip #3”
Comments are closed.