Internal error in EmptyDataProviderRule with a named argument in `#[DataProvider]` (2.1.3)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 63/100
Direzione di ricerca
Inizia da src/Rules/PHPUnit/EmptyDataProviderRule.php, dove processNode chiama isDataProvider (intorno alle righe 75 e 100), e verifica come DataProviderHelper::yieldDataProviderAttributes legge il primo argomento dell'attributo. Riproduci il problema con lo snippet ReproTest.php della issue, usando #[DataProvider(methodName: 'provideValues')] e includendo bleedingEdge.neon. È completato quando il caso con argomento nominato non provoca più l'errore interno strcasecmp e un test lo copre.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PHP
- Stelle
- 547
- Fork
- 61
- Merge medio
- 1g 9h
- PR unite (30g)
- 13
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di phpstan/phpstan-phpunit
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
phpstan/phpstan-phpunit#321 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
phpstan/phpstan-phpunit#309 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
phpstan/phpstan-phpunit#299 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
phpstan/phpstan-phpunit#292 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
phpstan/phpstan-phpunit#291 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di phpstan/phpstan-phpunit
Issue simili
-
bug needs grooming
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
HE-Arc/le-panier-du-coin#49 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 2 giorni
-
15.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·