Internal error in EmptyDataProviderRule with a named argument in `#[DataProvider]` (2.1.3)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 src/Rules/PHPUnit/EmptyDataProviderRule.php 开始,查看 processNode 调用 isDataProvider 的位置(约第 75 和 100 行),并检查 DataProviderHelper::yieldDataProviderAttributes 如何读取第一个属性参数。使用 issue 中的 ReproTest.php 代码片段复现问题,采用 #[DataProvider(methodName: 'provideValues')],并包含 bleedingEdge.neon。当使用具名参数的情况不再触发 strcasecmp 内部错误,并且有测试覆盖该情况时,即完成。
由索引模型根据 Issue 内容生成。
描述
We know that PHPUnit marks its attributes with @no-named-arguments, so #[DataProvider(methodName: '...')] is not covered by its BC promise and this may well be on our side. Still, it worked in 2.1.2 and now PHPStan stops with an internal error instead of a reported error, so I wanted to let you know.
Versions: phpstan/phpstan-phpunit 2.1.3 (2.1.2 is fine), phpstan/phpstan 2.3.7, phpunit/phpunit 13.4.8, PHP 8.5.13. It happens only with bleedingEdge.neon included.
phpstan.neon:
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- phar://vendor/phpstan/phpstan/phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 0
paths:
- tests
tests/ReproTest.php:
<?php
declare(strict_types=1);
namespace Repro;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class ReproTest extends TestCase
{
#[DataProvider(methodName: 'provideValues')]
public function testValue(int $value): void
{
if ($value === 0) {
return;
}
self::assertSame(1, $value);
}
/**
* @return list<array{int}>
*/
public static function provideValues(): array
{
return [[0], [1]];
}
}
Result:
Internal error: strcasecmp(): Argument #1 ($string1) must be of type string, null given while analysing file /tmp/repro/tests/ReproTest.php
#0 vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/EmptyDataProviderRule.php(100): strcasecmp()
#1 vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/EmptyDataProviderRule.php(75): PHPStan\Rules\PHPUnit\EmptyDataProviderRule->isDataProvider()
#2 phar://vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyserCallback.php(168): PHPStan\Rules\PHPUnit\EmptyDataProviderRule->processNode()
With #[DataProvider('provideValues')] there is no error.
It looks like #354 changed return [] to continue for a bare return;, so a method like testValue() now reaches isDataProvider(). There, DataProviderHelper::yieldDataProviderAttributes() reads the attribute through reflection as $args[0], which is null when the argument is named (the key is methodName).
Skipping the attribute, or reading $args['methodName'] ?? $args[0] ?? null, would be enough for us. If you prefer to keep named arguments unsupported, that is fine too, we will switch to positional arguments.
- 主要语言
- PHP
- 星标
- 547
- 派生
- 61
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 13
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
phpstan/phpstan-phpunit 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
phpstan/phpstan-phpunit#321 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
phpstan/phpstan-phpunit#309 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
phpstan/phpstan-phpunit#299 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 52/100
phpstan/phpstan-phpunit#292 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 20/100
phpstan/phpstan-phpunit#291 ·
维护者通常 1 天内回复
查看 phpstan/phpstan-phpunit 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
HE-Arc/le-panier-du-coin#49 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 2 天内回复
-
15.0
难度 2/5 1-3 小时 新手友好度 65/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
LinkNacional/woo-rede#367 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复