pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: closures as dataset argument values no longer supported

Open ragulka opened this issue 1 year ago • 0 comments

What Happened

The following used to work with Pest v2, but throws ErrorException: Undefined array key "user" in Pest v3

it('demonstrates the issue', function (User $user, mixed $expectedResult) {
    // assert here
})->with(function() {
    yield 'caseA' => [
        'user' => fn() => User::factory()->create(),
        'expectedResult' => true,
    ];
    
    yield 'caseB' => [
        'user' => fn() => User::factory()->create(),
        'expectedResult' => false,
    ];
});

In Pest v3, all arguments must be wrapped in a closure, instead:

it('demonstrates the issue', function (User $user, mixed $expectedResult) {
    // assert here
})->with(function() {
    yield 'caseA' => fn() => [
        'user' => User::factory()->create(),
        'expectedResult' => true,
    ];
    
    yield 'caseB' => fn() => [
        'user' => User::factory()->create(),
        'expectedResult' => false,
    ];
});

The main issue is that this seems to be an undocumented breaking change.

How to Reproduce

See above

Sample Repository

No response

Pest Version

3.10

PHP Version

8.3

Operation System

macOS

Notes

No response

ragulka avatar Sep 20 '24 14:09 ragulka