Type Inference Issue with Named Parameters in PHPUnit Assertions Leading to Mixed Type Error in PHPStan
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start by reproducing the PHPStan error with the shown request data and PHPUnit assertions, comparing the positional and named-parameter forms of assertIsString. Trace how the assertion affects the inferred type of $data['result']['data']['id']; done means the named-parameter form preserves a string type for Uuid::fromString() without the mixed-type error.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hello,
I've encountered a type inference issue when using PHPStan with PHPUnit assertions on a piece of code that utilizes named parameters.
Given the following code snippet:
$data = $this->requestAndGetData(method: 'segment.create', parameters: [
'name' => 'Test segment'
]);
self::assertArrayHasKey(key: 'id', array: $data['result']['data']);
self::assertIsString($data['result']['data']['id']);
$segmentId = $data['result']['data']['id'];
$segmentUuid = Symfony\Component\Uid\Uuid::fromString(uuid: $segmentId);
The package operates correctly, and I am confident that the $segmentId variable is a string. However, after modifying the assertIsString assertion to use a named parameter:
self::assertIsString(actual: $data['result']['data']['id']);
I start receiving the following error from PHPStan:
Parameter $uuid of static method Symfony\Component\Uid\Uuid::fromString() expects string, mixed given.
This issue does not occur when the named parameter is not used in the assertion.
Thank you for your time and assistance.
- Lingua principale
- PHP
- Stelle
- 544
- Fork
- 58
- Merge medio
- 2g 1h
- PR unite (30g)
- 5
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
phpstan/phpstan-phpunit#332 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
phpstan/phpstan-phpunit#321 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
phpstan/phpstan-phpunit#309 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
phpstan/phpstan-phpunit#299 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
phpstan/phpstan-phpunit#292 · 3 commenti ·
Tutte le issue di phpstan/phpstan-phpunit
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
-
Admissions heading updates Apertaa11y admissions.uiowa.edu needs grooming SiteImprove best practice
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Save States Menu Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
pluginsGLPI/datainjection#673 ·