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
-
bug needs grooming
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
難度 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
-
難度 2/5 1-3 小時 新手友好度 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·