pest icon indicating copy to clipboard operation
pest copied to clipboard

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

Open michael-rubel opened this issue 1 year ago • 12 comments

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.

michael-rubel avatar Oct 10 '23 08:10 michael-rubel

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?

devajmeireles avatar Oct 10 '23 13:10 devajmeireles

@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 avatar Oct 10 '23 14:10 michael-rubel

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

Screenshot_5

michael-rubel avatar Oct 10 '23 14:10 michael-rubel

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

michael-rubel avatar Oct 10 '23 16:10 michael-rubel

@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?

devajmeireles avatar Oct 10 '23 16:10 devajmeireles

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

nunomaduro avatar Oct 10 '23 16:10 nunomaduro

@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?

michael-rubel avatar Oct 11 '23 09:10 michael-rubel

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

fabio-ivona avatar Oct 17 '23 05:10 fabio-ivona

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()

aymanalhattami avatar Feb 10 '24 06:02 aymanalhattami