Skip to content

Commit 75c685f

Browse files
committed
add tests for phpunit9
1 parent 086c0bb commit 75c685f

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

tests/Rules/PHPUnit/DataProviderDataRuleTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
class DataProviderDataRuleTest extends RuleTestCase
1616
{
17+
private ?int $phpunitVersion;
1718

1819
protected function getRule(): Rule
1920
{
@@ -24,13 +25,13 @@ protected function getRule(): Rule
2425
new DataProviderDataRule(
2526
new TestMethodsHelper(
2627
self::getContainer()->getByType(FileTypeMapper::class),
27-
new PHPUnitVersion(10)
28+
new PHPUnitVersion($this->phpunitVersion)
2829
),
2930
new DataProviderHelper(
3031
$reflectionProvider,
3132
self::getContainer()->getByType(FileTypeMapper::class),
3233
self::getContainer()->getService('defaultAnalysisParser'),
33-
new PHPUnitVersion(10)
34+
new PHPUnitVersion($this->phpunitVersion)
3435
),
3536

3637
),
@@ -42,6 +43,8 @@ protected function getRule(): Rule
4243

4344
public function testRule(): void
4445
{
46+
$this->phpunitVersion = 10;
47+
4548
$this->analyse([__DIR__ . '/data/data-provider-data.php'], [
4649
[
4750
'Parameter #2 $input of method DataProviderDataTest\FooTest::testWithAttribute() expects string, int given.',
@@ -176,6 +179,8 @@ public function testRulePhp8(): void
176179
self::markTestSkipped();
177180
}
178181

182+
$this->phpunitVersion = 10;
183+
179184
$this->analyse([__DIR__ . '/data/data-provider-data-named.php'], [
180185
[
181186
'Parameter $input of method DataProviderDataTestPhp8\NamedArgsInProvider::testFoo() expects string, int given.',
@@ -203,6 +208,8 @@ public function testRulePhp8(): void
203208

204209
public function testVariadicMethod(): void
205210
{
211+
$this->phpunitVersion = 10;
212+
206213
$this->analyse([__DIR__ . '/data/data-provider-variadic-method.php'], [
207214
[
208215
'Method DataProviderVariadicMethod\FooTest::testProvide2() invoked with 1 parameter, at least 2 required.',
@@ -241,6 +248,8 @@ public function testVariadicMethod(): void
241248

242249
public function testTrimmingArgs(): void
243250
{
251+
$this->phpunitVersion = 10;
252+
244253
$this->analyse([__DIR__ . '/data/data-provider-trimming-args.php'], [
245254
[
246255
'Method DataProviderTrimmingArgs\FooTest::testProvide() invoked with 2 parameters, 1 required.',

tests/Rules/PHPUnit/DataProviderDeclarationRuleTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
class DataProviderDeclarationRuleTest extends RuleTestCase
1313
{
14+
private ?int $phpunitVersion;
1415

1516
protected function getRule(): Rule
1617
{
@@ -21,7 +22,7 @@ protected function getRule(): Rule
2122
$reflection,
2223
self::getContainer()->getByType(FileTypeMapper::class),
2324
self::getContainer()->getService('defaultAnalysisParser'),
24-
new PHPUnitVersion(10)
25+
new PHPUnitVersion($this->phpunitVersion)
2526
),
2627
true,
2728
true
@@ -30,6 +31,8 @@ protected function getRule(): Rule
3031

3132
public function testRule(): void
3233
{
34+
$this->phpunitVersion = 10;
35+
3336
$this->analyse([__DIR__ . '/data/data-provider-declaration.php'], [
3437
[
3538
'@dataProvider providebaz related method is used with incorrect case: provideBaz.',
@@ -70,8 +73,34 @@ public function testRule(): void
7073
]);
7174
}
7275

76+
public function testRulePhpUnit9(): void
77+
{
78+
$this->phpunitVersion = 9;
79+
80+
$this->analyse([__DIR__ . '/data/data-provider-declaration.php'], [
81+
[
82+
'@dataProvider providebaz related method is used with incorrect case: provideBaz.',
83+
16,
84+
],
85+
[
86+
'@dataProvider provideQuux related method must be public.',
87+
16,
88+
],
89+
[
90+
'@dataProvider provideNonExisting related method not found.',
91+
70,
92+
],
93+
[
94+
'@dataProvider NonExisting::provideNonExisting related class not found.',
95+
70,
96+
],
97+
]);
98+
}
99+
73100
public function testFixDataProviderStatic(): void
74101
{
102+
$this->phpunitVersion = 10;
103+
75104
$this->fix(__DIR__ . '/data/data-provider-static-fix.php', __DIR__ . '/data/data-provider-static-fix.php.fixed');
76105
}
77106

0 commit comments

Comments
 (0)