PHPUnit @dataProvider simply doesn't work

php, phpunit

Solution

Finally after hours of prodding this test file, I discovered that merely defining the constructor function breaks the functionality of data providers. Good to know.

To fix it, just call the parent constructor. Here's how that looked in my case:

public function __construct()
{
    // Truncate the OmniDataManager tables
    R::wipe(OmniDataManager::TABLE_GROUP);
    R::wipe(OmniDataManager::TABLE_DATA);

    parent::__construct();   // <- Necessary
}

As David Harkness and Vasily pointed out in the comments, the constructor override must match the call signature of the base class constructor. In my case the base class constructor didn't require any arguments. I'm not sure if this has just changed in newer versions of phpunit or if it depends on your use case.

In any case, Vasily's example might work better for you:

public function __construct($name = null, array $data = array(), $dataName = '')
{
    // Your setup code here

    parent::__construct($name, $data, $dataName)
}

Problem

I've read the documentation on the topic, and my code follows all requirements of a data provider implementation. First of all, here's the full code of the test just in case it's relevant. Here's the function implementing data provider: ``` /** * Test the createGroup function * * @return void * @author Tomas Sandven <tomas191191@gmail.com> * * @dataProvider provideFileImportTests_good **/ public function testCreateGroup($file, $groupname, $group, $mapping) { // Create a test group $id = $this->odm->createGroup($groupname, $group); // Try to load it back out $result = R::load(OmniDataManager::TABLE_GROUP, $id); // Check that the result is not null $this->assertFalse(is_null($result)); return $id; } ``` PHPUnit just fails: Missing argument 1 for tests\broadnet\broadmap\OmniDataManagerTest::testCreateGroup() I've tried killing the application (`die();`) inside the data provider function, and it never happens. The data provider function is available publicly in the same class, there are no typos in the function name and the `testCreateGroup` function references it in the annotations in the comment, but the data provider function is never called. Does anybody know why?

Original source

Related problems