EcomDev_PHPUnit Tip #3

For years, the test framework EcomDev_PHPUnit is quasi-standard for Magento unit tests. The current version is 0.3.7 and last state of official documentation is version 0.2.0 – since then, much has changed which you have to search yourself in code and GitHub issues. This series shall collect practical usage tips.

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 thought on “EcomDev_PHPUnit Tip #3

Leave a Reply

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