Type Inference Issue with Named Parameters in PHPUnit Assertions Leading to Mixed Type Error in PHPStan
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- PHP
- Étoiles
- 544
- Forks
- 58
- Merge moyen
- 2 j 1 h
- PR mergées (30 j)
- 5
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de phpstan/phpstan-phpunit
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
phpstan/phpstan-phpunit#332 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
phpstan/phpstan-phpunit#321 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
phpstan/phpstan-phpunit#309 ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
phpstan/phpstan-phpunit#299 · 2 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 52/100
phpstan/phpstan-phpunit#292 · 3 commentaires ·
Toutes les issues de phpstan/phpstan-phpunit
Issues similaires
-
sync-en
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
-
sync-en
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
-
Перевод устарел
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
-
priority: p3
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
nextcloud/fulltextsearch#1011 ·