New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Provider Argument Count Error #2400
Comments
I'm not able to reproduce the issue with your provided information. Here's what I did:
This is the test class I used: use PHPUnit\Framework\TestCase;
class TestMeTest extends TestCase
{
protected $validation;
protected function setUp()
{
$this->validation = new Validation();
}
/**
* @covers ::validateType
* @dataProvider validateTypeProdiver
*/
public function testValidateType($assertion, $argument, $type)
{
$result = $this->validation->validateType($argument, $type);
switch ($assertion) {
case 'True':
$this->assertTrue($result);
break;
}
}
public function validateTypeProdiver()
{
return [
['True', 'file.txt', 'str']
];
}
} And the class Validation
{
public function validateType() {
return true;
}
} PHPUnit does not cache data providers persistently. |
I also cannot reproduce this. |
If somebody somewhen encountered this problem. class Test extends TestCase {
protected $tested;
public function __construct()
{
parent::__construct();
$this->tested = new TestedClass();
}
public function provider(): array
{
return array(
array(0, 1, 1),
array(1, 2, 3),
);
}
/**
* @dataProvider provider
*/
public function testSum(int $first, int $second, int $expected)
{
$this->assertEquals($expected, $this->tested->sum($first + $second));
}
} I changed __construct to setUp and it works. |
@dmirogin's solution made my day, phpunit 8.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using the latest version of PHPUnit (5.7.4). The problem is when I run test, it passes. But if I run it once again, it fails with the following error:
If I make any changes to the data provider function (i.e. change the data to be returned, provider function name or type etc.) and re-run, it passes for once and fails with the above error for all consecutive test runs.
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
ortearDown
)?The following code work once (pass once):
The following code always work (passes everytime):
The text was updated successfully, but these errors were encountered: