-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Constructor in subclass of PHPUnit_Framework_TestCase causes @dataProvider to break #621
Comments
Expected behaviour. If you override |
Thank you for the clarification. However, the constructor in PHPUnit_Framework_TestCase provides default values for its arguments and they are defined the same anyway. Calling it should make no difference unless you specifically want to change something. Moreover this isn't mentioned in the docs (http://www.phpunit.de/manual/current/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestCase) and the DBUnit BankAccount sample even does this (https://github.com/sebastianbergmann/dbunit/blob/master/Samples/BankAccountDB/BankAccountDBTest.php#L60). I wouldn't say it was expected behaviour if some annotations work and some do not just because of this. |
I have solved the problem like this: class Test extends PHPUnit_Framework_TestCase { |
Hi, My case is like this and it fails. # my base test class
use PHPUnit_Framework_TestCase;
class mytest extends PHPUnit_Framework_TestCase {
public function __construct() {
# do some common stuff to my tests...
}
}
class IntegrationTest extends mytest {
public function __construct() {
parent::__construct();
}
/**
* @dataProvider additionProvider
*/
public function testAdd($a, $b, $expected)
{
$this->assertEquals($expected, $a + $b);
}
public function additionProvider()
{
return [
'adding zeros' => [0, 0, 0],
'zero plus one' => [0, 1, 1],
'one plus zero' => [1, 0, 1],
'one plus one' => [1, 1, 3]
];
}
} fixed and working version looks like this # my base test class
use PHPUnit_Framework_TestCase;
class mytest extends PHPUnit_Framework_TestCase {
public function __construct() {
# do some common stuff to my tests...
parent::__construct(...func_get_args());
}
}
class IntegrationTest extends mytest {
public function __construct($name = NULL, array $data = array(), $dataName = '') {
parent::__construct(...func_get_args());
}
/**
* @dataProvider additionProvider
*/
public function testAdd($a, $b, $expected)
{
$this->assertEquals($expected, $a + $b);
}
public function additionProvider()
{
return [
'adding zeros' => [0, 0, 0],
'zero plus one' => [0, 1, 1],
'one plus zero' => [1, 0, 1],
'one plus one' => [1, 1, 3]
];
}
} Current PHPUnit documentation does not warn in any ways that do not add custom __constructor() for your tests classes which are using dataProvider. That information could be added in to current Data Providers documentation, at least it would give you a hint why your implementation is not working even if you copy-pasted the example dataProvider code. Ping because closed @sebastianbergmann |
Having a constructor in your test causes the dataProvider annotation to break with an error about missing arguments:
Removing the constructor causes the testTheProvider to work again, and does not seem to break @Depends annotations.
The text was updated successfully, but these errors were encountered: