Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/.phpstan/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"phpstan/phpstan-strict-rules": "^2.1.1",
"ergebnis/phpstan-rules": "^2.17.1",
"phpstan/phpstan-deprecation-rules": "^2.0.5",
"phpstan/phpstan-phpunit": "^2.1.1"
"phpstan/phpstan-phpunit": "^2.1.2"
},
"config": {
"allow-plugins": {
Expand Down
16 changes: 8 additions & 8 deletions tools/.phpstan/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions tools/.phpstan/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,17 @@
},
{
"name": "phpstan/phpstan-phpunit",
"version": "2.1.1",
"version_normalized": "2.1.1.0",
"version": "2.1.2",
"version_normalized": "2.1.2.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-phpunit.git",
"reference": "8d16b8478e523a47f8c02e83bce8981b5b5a3b03"
"reference": "ffff35d4f96c4642d7f41a3515d90afa0f58be62"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/8d16b8478e523a47f8c02e83bce8981b5b5a3b03",
"reference": "8d16b8478e523a47f8c02e83bce8981b5b5a3b03",
"url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/ffff35d4f96c4642d7f41a3515d90afa0f58be62",
"reference": "ffff35d4f96c4642d7f41a3515d90afa0f58be62",
"shasum": ""
},
"require": {
Expand All @@ -425,8 +425,8 @@
"phpunit/phpunit": "^9.6",
"shipmonk/name-collision-detector": "^2.1"
},
"time": "2026-10-06T18:12:32+00:00",
"published-time": "2026-10-07T04:59:27+00:00",
"time": "2026-11-12T15:27:53+00:00",
"published-time": "2026-11-12T16:07:51+00:00",
"type": "phpstan-extension",
"extra": {
"phpstan": {
Expand All @@ -452,7 +452,7 @@
],
"support": {
"issues": "https://github.com/phpstan/phpstan-phpunit/issues",
"source": "https://github.com/phpstan/phpstan-phpunit/tree/2.1.1"
"source": "https://github.com/phpstan/phpstan-phpunit/tree/2.1.2"
},
"install-path": "../phpstan/phpstan-phpunit"
},
Expand Down
10 changes: 5 additions & 5 deletions tools/.phpstan/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => '12.5.x-dev',
'version' => '12.5.9999999.9999999-dev',
'reference' => 'a64a3ee050b3f843e2386f3784d26ca69797ad4a',
'reference' => '4cd679699a37205fc46737d47a9be4a27142a22a',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => '12.5.x-dev',
'version' => '12.5.9999999.9999999-dev',
'reference' => 'a64a3ee050b3f843e2386f3784d26ca69797ad4a',
'reference' => '4cd679699a37205fc46737d47a9be4a27142a22a',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -74,9 +74,9 @@
'dev_requirement' => true,
),
'phpstan/phpstan-phpunit' => array(
'pretty_version' => '2.1.1',
'version' => '2.1.1.0',
'reference' => '8d16b8478e523a47f8c02e83bce8981b5b5a3b03',
'pretty_version' => '2.1.2',
'version' => '2.1.2.0',
'reference' => 'ffff35d4f96c4642d7f41a3515d90afa0f58be62',
'type' => 'phpstan-extension',
'install_path' => __DIR__ . '/../phpstan/phpstan-phpunit',
'aliases' => array(),
Expand Down
6 changes: 6 additions & 0 deletions tools/.phpstan/vendor/phpstan/phpstan-phpunit/rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ conditionalTags:
PHPStan\Rules\PHPUnit\ClassAttributeRequiresPhpVersionRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%

PHPStan\Rules\PHPUnit\EmptyDataProviderRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%

services:
-
class: PHPStan\Rules\PHPUnit\DataProviderDeclarationRule
Expand All @@ -46,3 +49,6 @@ services:

-
class: PHPStan\Rules\PHPUnit\DataProviderDataRule

-
class: PHPStan\Rules\PHPUnit\EmptyDataProviderRule
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php declare(strict_types = 1);

namespace PHPStan\Rules\PHPUnit;

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\MethodReturnStatementsNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPUnit\Framework\TestCase;
use function sprintf;
use function strcasecmp;

/**
* @implements Rule<MethodReturnStatementsNode>
*/
class EmptyDataProviderRule implements Rule
{

private TestMethodsHelper $testMethodsHelper;

private DataProviderHelper $dataProviderHelper;

private PHPUnitVersion $PHPUnitVersion;

public function __construct(
TestMethodsHelper $testMethodsHelper,
DataProviderHelper $dataProviderHelper,
PHPUnitVersion $PHPUnitVersion
)
{
$this->testMethodsHelper = $testMethodsHelper;
$this->dataProviderHelper = $dataProviderHelper;
$this->PHPUnitVersion = $PHPUnitVersion;
}

public function getNodeType(): string
{
return MethodReturnStatementsNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
// A generator yields its data sets one at a time, so whether it provides
// any depends on control flow this rule cannot decide.
if ($node->isGenerator()) {
return [];
}

$returnStatements = $node->getReturnStatements();
if ($returnStatements === []) {
return [];
}

if ($this->PHPUnitVersion->rejectsEmptyDataProviders()->no()) {
return [];
}

if (!$node->getClassReflection()->is(TestCase::class)) {
return [];
}

foreach ($returnStatements as $returnStatement) {
$returnExpr = $returnStatement->getReturnNode()->expr;
if ($returnExpr === null) {
return [];
}

$returnType = $returnStatement->getScope()->getType($returnExpr);
if (!$returnType->isIterable()->yes() || !$returnType->isIterableAtLeastOnce()->no()) {
return [];
}
}

if (!$this->isDataProvider($node, $scope)) {
return [];
}

return [
RuleErrorBuilder::message(sprintf(
'Data provider method %s() provides no data sets, which is an error in PHPUnit 10 and newer.',
$node->getMethodName(),
))
->identifier('phpunit.dataProviderEmpty')
->build(),
];
}

private function isDataProvider(MethodReturnStatementsNode $node, Scope $scope): bool
{
$classReflection = $node->getClassReflection();

foreach ($this->testMethodsHelper->getTestMethods($classReflection, $scope) as $testMethod) {
foreach ($this->dataProviderHelper->getDataProviderMethods($scope, $testMethod, $classReflection) as [$providerClassReflection, $providerMethodName]) {
// A provider declared in another class is checked when that class is analysed.
if ($providerClassReflection === null || $providerClassReflection->getName() !== $classReflection->getName()) {
continue;
}

if (strcasecmp($providerMethodName, $node->getMethodName()) === 0) {
return true;
}
}
}

return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public function requiresStaticDataProviders(): TrinaryLogic
return TrinaryLogic::createFromBoolean($this->majorVersion >= 10);
}

public function rejectsEmptyDataProviders(): TrinaryLogic
{
if ($this->majorVersion === null) {
return TrinaryLogic::createMaybe();
}
return TrinaryLogic::createFromBoolean($this->majorVersion >= 10);
}

public function supportsNamedArgumentsInDataProvider(): TrinaryLogic
{
if ($this->majorVersion === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ private static function getExpressionResolvers(): array
new FuncCall(new Name('count'), [$actual]),
),
),
'GreaterThan' => static fn (Scope $scope, Arg $expected, Arg $actual): Expr\BinaryOp\Greater => new Expr\BinaryOp\Greater(
$actual->value,
$expected->value,
),
'LessThan' => static fn (Scope $scope, Arg $expected, Arg $actual): Expr\BinaryOp\Smaller => new Expr\BinaryOp\Smaller(
$actual->value,
$expected->value,
),
'InstanceOf' => static fn (Scope $scope, Arg $class, Arg $object): Instanceof_ => new Instanceof_(
$object->value,
$class->value,
Expand Down
Loading