Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c4597bf
Implement DataProviderDataRule
staabm Oct 13, 2025
ccff992
report correct line
staabm Oct 13, 2025
0975030
Added DataProviderDataRuleTest
staabm Oct 13, 2025
5c6445a
implement CompositeRule
staabm Oct 13, 2025
ff6843e
cleanup
staabm Oct 13, 2025
1dd180c
Implement reflection based dataprovider detection
staabm Oct 13, 2025
cff1f79
cs
staabm Oct 13, 2025
0ab211d
simplify
staabm Oct 13, 2025
7f7b38b
fix
staabm Oct 13, 2025
d74aeec
Refactor
staabm Oct 14, 2025
09b226b
test annotations
staabm Oct 14, 2025
f9c8af7
support yield
staabm Oct 14, 2025
d3a2b9b
support yield from
staabm Oct 14, 2025
f42bd8a
fix
staabm Oct 14, 2025
3318b73
Support `test` annotation and attribute
staabm Oct 14, 2025
f715fbf
extract PHPUnitVersionDetector
staabm Oct 14, 2025
67a40d6
fix php 7.4
staabm Oct 14, 2025
6f4dcc9
cs
staabm Oct 14, 2025
20d1408
bleeding edge only
staabm Oct 14, 2025
5cb8c63
test too many/few arguments
staabm Oct 14, 2025
72d5655
report too many/too few with when provider re-used
staabm Oct 14, 2025
1453c20
cleanup
staabm Oct 14, 2025
1506a06
Update extension.neon
staabm Oct 14, 2025
9b69121
use types
staabm Oct 14, 2025
459eb1d
support named args
staabm Oct 14, 2025
5fcf01d
fix invalid call on null
staabm Oct 14, 2025
a978aa8
fix invalid call on null in yield
staabm Oct 14, 2025
a1dad84
fix type error
staabm Oct 14, 2025
1d3db54
new TypeExpr(new ObjectType())
staabm Oct 14, 2025
7417fbc
test constant array return from delegated method
staabm Oct 14, 2025
74b67cf
use CompositeRule from phpstan-src
staabm Oct 14, 2025
5cb7312
fix PHP 7.4
staabm Oct 14, 2025
9ee26b1
Update data-provider-data.php
staabm Oct 14, 2025
4cb9404
test more variadics
staabm Oct 14, 2025
34a0a0e
more variadic tests
staabm Oct 14, 2025
bb855f0
fix
staabm Oct 14, 2025
a56169b
Update DataProviderDataRuleTest.php
staabm Oct 14, 2025
e31a234
Update DataProviderDataRule.php
staabm Oct 14, 2025
1532c26
support iterables
staabm Oct 14, 2025
68e65e9
test ArrayIterator
staabm Oct 14, 2025
30e27db
cleanup
staabm Oct 15, 2025
aafaf8f
simplify
staabm Oct 15, 2025
b6f11fe
Report wrongly typed generic arrays
staabm Oct 15, 2025
72dc9e0
simplify
staabm Oct 15, 2025
ccb7b04
Fix SA error
ondrejmirtes Oct 16, 2025
8491dd7
Fix CS
ondrejmirtes Oct 16, 2025
aea7e42
abstract test-class
staabm Oct 17, 2025
a1e5a19
factor out buildArrayTypesFromNode()
staabm Oct 17, 2025
7f9dbf2
test more const array variants
staabm Oct 17, 2025
c689efe
special case for providers only containing static data, so we get mor…
staabm Oct 17, 2025
d6c11be
apply static data only special case also for "yield from"
staabm Oct 17, 2025
21740cb
moved cheapest check to the front
staabm Oct 17, 2025
41acc04
Failing test - args trimming logic needs some work
ondrejmirtes Oct 17, 2025
807a35f
Not a failing test, just checking :)
ondrejmirtes Oct 17, 2025
3fc4e0e
separated php8 only tests
staabm Oct 17, 2025
9a0d039
separate named args expectations
staabm Oct 17, 2025
daf978e
separated more named args tests
staabm Oct 17, 2025
534694d
fix arg trimming
staabm Oct 18, 2025
58461d7
more fixes
staabm Oct 18, 2025
b36a404
cs
staabm Oct 18, 2025
f083e63
Manual mutation testing ep. 1
ondrejmirtes Oct 18, 2025
42ad04e
Manual mutation testing ep. 2
ondrejmirtes Oct 18, 2025
0731026
break
ondrejmirtes Oct 18, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
staabm committed Oct 15, 2025
commit 30e27db0624ad78d35dd5548dc2eb96ce5b1bc9d
14 changes: 7 additions & 7 deletions src/Rules/PHPUnit/DataProviderDataRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public function processNode(Node $node, Scope $scope): array
$constantArrays = [];
$exprType = $scope->getType($node->expr);
$exprConstArrays = $exprType->getConstantArrays();
if ($exprConstArrays !== []) {
foreach ($exprConstArrays as $constArray) {
foreach ($constArray->getValueTypes() as $valueType) {
foreach ($valueType->getConstantArrays() as $constValueArray) {
$constantArrays[] = $constValueArray;
}
foreach ($exprConstArrays as $constArray) {
foreach ($constArray->getValueTypes() as $valueType) {
foreach ($valueType->getConstantArrays() as $constValueArray) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think awkward things will happen when the count of $exprType->getConstantArrays() or $valueType->getConstantArrays() are > 1. Those are unions of arrays.

So you'll treat array{1}|array{2} as two separate test case invocations, but they're not really? It's more like a single invocation with 1|2.

But I don't know what to do about arrays of different lengths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a few more const array tests. I did not yet experience something awkward.

do you have something specific in mind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$constantArrays[] = $constValueArray;
}
}
} else {
}

if ($constantArrays === []) {
$constantArrays = $exprType->getIterableValueType()->getConstantArrays();
}
} elseif ($node instanceof Node\Expr\Yield_) {
Expand Down
10 changes: 5 additions & 5 deletions tests/Rules/PHPUnit/DataProviderDataRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
$reflectionProvider = $this->createReflectionProvider();

return new CompositeRule([

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, lowest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, lowest, ^12.0.9)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, lowest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, lowest, ^11.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, highest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, lowest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, highest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, highest, ^11.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, highest, ^11.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, lowest, ^11.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, lowest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, highest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, lowest, ^12.0.9)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, lowest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, highest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, lowest, ^11.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, highest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, lowest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, highest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, highest, ^12.0.9)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, highest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, highest, ^12.0.9)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, highest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, lowest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, highest, ^10.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, highest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, lowest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, lowest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, highest, ^11.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.

Check failure on line 24 in tests/Rules/PHPUnit/DataProviderDataRuleTest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, lowest, ^9.5)

Parameter #1 $rules of class PHPStan\Testing\CompositeRule constructor expects array<PHPStan\Rules\Rule<PhpParser\Node>>, array{PHPStan\Rules\PHPUnit\DataProviderDataRule, PHPStan\Rules\Methods\CallMethodsRule} given.
new DataProviderDataRule(
new TestMethodsHelper(
self::getContainer()->getByType(FileTypeMapper::class),
Expand Down Expand Up @@ -139,24 +139,24 @@
355,
],
[
'Unknown parameter $foo in call to method DataProviderDataTest\TestIterable::testBar().',
'Unknown parameter $foo in call to method DataProviderDataTest\TestArrayShapeIterable::testBar().',
371,
],
[
'Missing parameter $si (int) in call to method DataProviderDataTest\TestIterable::testBar().',
'Missing parameter $si (int) in call to method DataProviderDataTest\TestArrayShapeIterable::testBar().',
371,
],
[
'Parameter #1 $i of method DataProviderDataTest\TestArrayIterator::testBar() expects int, int|string given.',
401,
421,
],
[
'Parameter #1 $i of method DataProviderDataTest\TestArrayIterator::testFoo() expects int, int|string given.',
401,
421,
],
[
'Parameter #1 $s1 of method DataProviderDataTest\TestArrayIterator::testFooBar() expects string, int|string given.',
401,
421,
],
]);
}
Expand Down
22 changes: 21 additions & 1 deletion tests/Rules/PHPUnit/data/data-provider-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function aProvider(): iterable
}
}

class TestIterable extends TestCase
class TestArrayShapeIterable extends TestCase
{
/** @dataProvider aProvider */
public function testBar(int $si): void
Expand All @@ -379,6 +379,26 @@ public function data(): iterable
}
}

class TestTypedIterable extends TestCase
{
/** @dataProvider aProvider */
public function testBar(int $si): void
{
}

public function aProvider(): iterable
{
return $this->data();
}

/**
* @return iterable<array<int>>
*/
public function data(): iterable
{
}
}

class TestArrayIterator extends TestCase
{
/** @dataProvider aProvider */
Expand Down
Loading