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.48k stars 343 forks source link

Calling seeders in beforeAll #1094

Open mokhosh opened 7 months ago

mokhosh commented 7 months ago

What Happened

Imagine if you have a large seeder that takes 5s to run, and you need to test 20 things after that seed.

If you seed at the beginning of each test you would be waiting a 100 seconds for those tests, but if you could run the seeder once, it will take about 5 seconds, which is a massive improvement.

Please provide a way for us to do this:

beforeAll(fn () => seed());

This is also mentioned in #237 and #246 and https://github.com/pestphp/pest/issues/33#issuecomment-658022624 but sadly they are closed and ignored, but this seems to be a big pain point and a deal breaker for a lot of people.

How to Reproduce

Do beforeAll(fn () => seed()); in a pest test file and you will get this:

  assert(array_key_exists(self::FILE, $trace))

  at tests/Unit/SomeTest.php:7
      3▕ use function Pest\Laravel\assertDatabaseHas;
      4▕ use function Pest\Laravel\seed;
      5▕ 
      6▕ beforeAll(function () {
  ➜   7▕     seed();
      8▕ });

Pest Version

2.33.66

PHP Version

8.3.2

Operation System

macOS

GolearnMkieler commented 1 month ago

Still no fix for this i guess.. Why is this ignored?!

djurovicigoor commented 2 weeks ago

Need this...

djurovicigoor commented 2 weeks ago

@nunomaduro