lundi 19 décembre 2016

PHPUnit Data Provider Argument Count Error

I have just started using PHPUnit. So far, everything is going perfect except the Data Provider issue.

The problem is when I run test, it passes. But if I run it once again, it fails with the following error:

ArgumentCountError: Too few arguments to function ValidationTest::testValidateType(), 0 passed and at least 3 expected

If I make any changes to the data provider function (i.e. change the data to be returned, provider function name etc.) and re-run, it passes for once and fails with the above error for all consecutive test runs.

I am using the latest version of PHPUnit (updated an hour ago). Unfortunately I did not find any specific solution anywhere. So, I am really worried, am I doing very silly mistake(s)?

Not sure, but does PHPUnit use any caching mechanism to cache provider data? If yes, then is there any way to clean it (maybe using setUp or tearDown)?

Look forward to seeing expert opinions. Thanks in advance. :-)


Please find the code bellow:

/**
 * @covers Validation
 * @coversDefaultClass Validation
 */
class ValidationTest extends TestCase {

    protected $validation;


    protected function setUp() {
        $this->validation = new Validation();
    }


    /**
     * @covers ::validateType
     * @dataProvider validateTypeProdiver
     */
    public function testValidateType($assertion, $argument, $type) {
        switch ($assertion) {
            case 'True':
                $this->assertTrue(
                    $this->validation->validateType($argument, $type)
                );
                break;
        }
    }


    public function validateTypeProdiver() {
        return [
            ['True', 'file.txt', 'str']
       ];
    }
}

Aucun commentaire:

Enregistrer un commentaire