pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Could not bind closure.

Open raonikhil opened this issue 2 years ago • 3 comments

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

raonikhil avatar Nov 20 '23 11:11 raonikhil

$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.

owenvoke avatar Nov 20 '23 11:11 owenvoke

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

raonikhil avatar Nov 21 '23 05:11 raonikhil

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?

surgiie avatar Feb 24 '24 02:02 surgiie