Skip to content

[Bug]: pest-plugin-rector wrong refactor on array #1874

Description

@faissaloux

What Happened

My test is

expect($array)->each(function ($element): void {
    $element->value->toBeString();
});

expect($array)->toMatchArray([
    //
]);

When I run pest-plugin rector, it transformed it to

expect($array)->each(function ($element): void {
    $element->value->toBeString();
})->toMatchArray([
    //
]);

which is not correct.

Expected

expect($array)->each(function ($element): void {
    $element->value->toBeString();
})->and($array)->toMatchArray([
    //
]);

or reorder to

expect($array)->toMatchArray([
    //
])->each(function ($element): void {
    $element->value->toBeString();
});

How to Reproduce

expect($array)->each(function ($element): void {
    $element->value->toBeString();
});

expect($array)->toMatchArray([
    //
]);

then run pest-plugin-rector

Sample Repository

No response

Pest Version

5.0.5

PHP Version

8.4.15

Operation System

Windows, Linux

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions