Pest: Can't use empty array as one of dataset values

Created on 29 Sep 2020  路  5Comments  路  Source: pestphp/pest

Hey,

Just started using datasets (great feature 馃挴) and noticed this:

it('test empty user input processing', function ($param){
    expect(true)->toBeTrue();
})->with([
    null,
    []
]);

Screenshot 2020-09-29 at 19 23 58

Most helpful comment

I'd assume that's because the array is interpreted as a subset of parameters.

it('test empty user input processing', function ($param = null) {
    expect(true)->toBeTrue();
})->with([
    [null],
    [[]]
]);

Have a look at the second example in the documentation. 馃憤馃徎

All 5 comments

Your closure requires an $param. Update the code to:

it('foo', function ($param = null) { ..

@nunomaduro hmmm, it now received null in both cases but in the second one it should've received an empty array:

it('test empty user input processing', function ($param = null){
    dump($param);
    expect(true)->toBeTrue();
})->with([
    null,
    []
]);

Screenshot 2020-09-30 at 09 57 17

I'd assume that's because the array is interpreted as a subset of parameters.

it('test empty user input processing', function ($param = null) {
    expect(true)->toBeTrue();
})->with([
    [null],
    [[]]
]);

Have a look at the second example in the documentation. 馃憤馃徎

@owenvoke oh, nice, thanks! I saw it but it didn't seem applicable because it was indended for multiple arguments. :D

Perhaps we could update the docs to clarify that a bit more in the case of an empty array. 馃憤馃徎 Cheers.

Was this page helpful?
0 / 5 - 0 ratings