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.12k stars 319 forks source link

[Bug]: Could not bind closure. #1016

Open raonikhil opened 8 months ago

raonikhil commented 8 months ago

What Happened

PHP version: 8.2.8 Operating system: Linux str_replace(): Argument #3 ($subject) must be of type array|string, null given

at vendor/filp/whoops/src/Whoops/Exception/FrameCollection.php:43 39▕ @return FrameCollection 40▕ / 41▕ public function filter($callable) 42▕ { ➜ 43▕ $this->frames = array_values(array_filter($this->frames, $callable)); 44▕ return $this; 45▕ } 46▕ 47▕ /**

INFO Warning: Cannot unbind $this of closure using $this in /var/www/html/vendor/pestphp/pest/src/Support/Closure.php on line 27.

How to Reproduce

uses( Tests\TestCase::class, Illuminate\Foundation\Testing\RefreshDatabase::class, ) ->beforeAll(function() { $this->seed(); }) ->in('Feature');

Sample Repository

No response

Pest Version

2.24.3

PHP Version

8.2

Operation System

Linux

Notes

No response

owenvoke commented 8 months ago

$this->seed() requires the framework to be booted. Which requires the testcase to be booted. This can't be used within a beforeAll() usage, as it runs before the testcase has booted. 👍🏻 Try using beforeEach() instead.

raonikhil commented 8 months ago

$this->seed() requires the framework to be booted. Which requires the testcase to be booted. This can't be used within a beforeAll() usage, as it runs before the testcase has booted. 👍🏻 Try using beforeEach() instead.

But to run $this->seed() before each test case would not be very ideal, right? how to then ideally seed the db?

surgiie commented 4 months ago

I have a similar use case where i wish to run some code before all tests that is not ideal to run before each, is there any plans to offer a hook where the test suite/framework is available?