Type Inference Issue with Named Parameters in PHPUnit Assertions Leading to Mixed Type Error in PHPStan
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
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.
- Dominant language
- PHP
- Stars
- 544
- Forks
- 58
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 5
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-phpunit
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
phpstan/phpstan-phpunit#332 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#321 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-phpunit#309 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpstan/phpstan-phpunit#299 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
phpstan/phpstan-phpunit#292 · 3 comments ·
All issues in phpstan/phpstan-phpunit
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
coollabsio/coolify#11927 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100