Internal error in EmptyDataProviderRule with a named argument in `#[DataProvider]` (2.1.3)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 63/100
Hướng nghiên cứu
Bắt đầu từ src/Rules/PHPUnit/EmptyDataProviderRule.php, nơi processNode gọi isDataProvider (khoảng dòng 75 và 100), rồi kiểm tra cách DataProviderHelper::yieldDataProviderAttributes đọc đối số đầu tiên của attribute. Tái hiện lỗi bằng đoạn ReproTest.php trong issue, dùng #[DataProvider(methodName: 'provideValues')] và có bao gồm bleedingEdge.neon. Hoàn thành khi trường hợp dùng đối số có tên không còn gây lỗi nội bộ strcasecmp và có một test bao phủ nó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- PHP
- Star
- 547
- Fork
- 61
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phpstan/phpstan-phpunit
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-phpunit#321 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-phpunit#309 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
phpstan/phpstan-phpunit#299 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
phpstan/phpstan-phpunit#292 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
phpstan/phpstan-phpunit#291 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của phpstan/phpstan-phpunit
Issue tương tự
-
bug needs grooming
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
HE-Arc/le-panier-du-coin#49 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 2 ngày
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·