phpstan-phpunit icon indicating copy to clipboard operation
phpstan-phpunit copied to clipboard

Type Inference Issue with Named Parameters in PHPUnit Assertions Leading to Mixed Type Error in PHPStan

Open lukasojd opened this issue 8 months ago • 0 comments

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.

lukasojd avatar Nov 07 '23 14:11 lukasojd