pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.4k stars 336 forks source link

[Bug]: Upgrade of `collision` causes Pest to crash #978

Open michael-rubel opened 11 months ago

michael-rubel commented 11 months ago

What Happened

Typed static property P\Tests\Feature\MyTest::$__latestDescription must not be accessed before initialization

How to Reproduce

Use datasets and upgrade nunomaduro/collision to version 7.8.1 or higher.

Pest Version

2.22.0

PHP Version

8.2.3

Operation System

Linux

Notes

Downgrading nunomaduro/collision to 7.8.0 fixes the issue.

devajmeireles commented 11 months ago

Hey, @michael-rubel ! Thanks for your report.

I was unable to reproduce the issue based on a new Laravel project, for example. I'm interested in knowing why a Collision update was necessary?

michael-rubel commented 11 months ago

@devajmeireles I was doing a regular composer update in the project, and Pest crashed after that.

If that would help, all dependencies that were downgraded alongside collision to make it work again:

Screenshot_4

michael-rubel commented 11 months ago

With those versions, it does work. Still, upgrading only collision to 7.8.1 (without upgrading others) causes the error.

Screenshot_5

michael-rubel commented 11 months ago

@devajmeireles Seems the same as https://github.com/pestphp/pest/issues/963

devajmeireles commented 11 months ago

@devajmeireles I was doing a regular composer update in the project, and Pest crashed after that.

If that would help, all dependencies that were downgraded alongside collision to make it work again:

Screenshot_4

We continue unable to reproduce the issue. I've started a new Laravel project and updated the composer dependencies and all works fine after the update. Could you share a repository example, please?

nunomaduro commented 11 months ago

@michael-rubel Without a way to reproduce the issue locally, we can't help.

michael-rubel commented 11 months ago

@nunomaduro @devajmeireles

I found that this bug is triggered by https://github.com/nunomaduro/collision/pull/280/files#diff-401856c982d2b2da6aa98709f2114b7d9421aca0687db29a66d56db27b2ae6f5R232

But it seems the root cause is not this, but the fact that datasets stopped being loaded from the subfolders in a global Datasets folder:

Screenshot_8

Inside the Companies.php I have datasets like this:

Screenshot_10

If I move Companies.php to the Datasets root, then the $__latestDescription error disappears, and Pest starts working.

I'd create a PR to fix it, but it looks like it's something related to the getScopedDataset logic, and not sure what the author meant by str_starts_with($currentTestFile, $datasetScope) filtering condition in this case.

Also a thought: the project is quite old and we were upgrading the app from Pest 1.x to Pest 2.x. This change could have arrived in 2.x, but we haven't noticed that those tests were not running because PHPUnit internal errors were not reported?

fabio-ivona commented 11 months ago

I think dataset is not scoped correctly because it checks if it's parent folder is called Datasets, maybe we can fix it by extending the check to any parent folder in the filetree

aymanalhattami commented 7 months ago

I was having the same issue after upgrading to pest v2 and I found the bug in the Datasets.

Solution: Make sure to use \Pest\Faker\fake() not \Pest\Faker\faker()

CheesyTech commented 3 months ago

Hi, I have the same problem when declaring a dataset function using the Route facade. My dataset: fail_dataset

I was able to trace this problem back to the moment I received the application object, which for some reason was not initialized and i get error A facade root has not been set. image I assume it has something to do with the issue #704 As a temporary solution, the package helped me - lukeraymonddowning/pest-plugin-larastrap

SerendipityNL commented 2 months ago

Just to help others:

We had this issue when we used the Arr helper in a dataset, but did not add it to the use list at the top of the file. When testing in sail we didn't get an issue, but testing locally (like our pipeline) did.

The error had us chasing a totally different route, but just the use Illuminate\Support\Arr; fixed the error.

csfh commented 1 month ago

Just since this isn't closed yet, I came across and saw this. I believe this can simply happen if you try to use do ->with('<some-dataset-that-does-not-exists>').

i.e. make sure you are trying to use dataset that you created with dataset, and make sure it's loaded too.