Skip to content

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

Open
@lukasojd

Description

@lukasojd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions