pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Pest internally throws `$__latestDescription must not be accessed before initialization` when data provider returns empty array, instead of the expected `InvalidDataProviderException`

Open maples3 opened this issue 8 months ago • 0 comments

What Happened

Here is a minimal reproduction test case:

test('example', function () {
    expect(true)->toBeTrue();
})->with(function () {
    return [];
});

It looks like this is supposed to be throwing an InvalidDataProviderException exception alerting me that my data provider appears incorrect (src/Metadata/Api/DataProvider.php): Image

However, it is actually throwing a PHP error attempting to access the $__latestDescription variable: Image

How to Reproduce

  1. Create a brand new Composer project
  2. ./vendor/bin/pest --init
  3. Add the above minimal reproduction test case to the automatically-generated example unit test.

Sample Repository

No response

Pest Version

3.8.1

PHP Version

8.3.19

Operation System

Linux

Notes

As a side note, it would be helpful if there was a mechanism to indicate "I expect no datasets here".

I have a different open issue (https://github.com/pestphp/pest/issues/1369) regarding filtering of test, and my workaround is to return an empty dataset array when a CLI filter is provided. This workaround no longer works due to the InvalidDataProviderException, and it took a significant amount of time to realize that the $__latestDescription must not be accessed before initialization error was generated by Pest due to something going wrong when handling the InvalidDataProviderException

maples3 avatar Apr 07 '25 18:04 maples3