Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lukasojd opened this issue Nov 7, 2023 · 0 comments

Comments

@lukasojd
Copy link

lukasojd commented Nov 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant