pestphp/pest · error · BeforeAllAlreadyExist

The [beforeAll] hook is already defined in [%s]. Each test f

Error message

The [beforeAll] hook is already defined in [%s]. Each test file may only define it once.

What it means

Error "The [beforeAll] hook is already defined in [%s]. Each test file may only define it once." thrown in pestphp/pest.

Source

Thrown at src/Repositories/BeforeAllRepository.php:36

     * @var array<string, Closure>
     */
    private array $state = [];

    public function pop(string $filename): Closure
    {
        $closure = $this->get($filename);

        unset($this->state[$filename]);

        return $closure;
    }

    public function set(Closure $closure): void
    {
        $filename = Reflection::getFileNameFromClosure($closure);

        if (array_key_exists($filename, $this->state)) {
            throw new BeforeAllAlreadyExist($filename);
        }

        $this->state[$filename] = $closure;
    }

    public function get(string $filename): Closure
    {
        return $this->state[$filename] ?? NullClosure::create();
    }
}

View on GitHub (pinned to 1af74a215c)

When it happens

Trigger: Thrown at src/Repositories/BeforeAllRepository.php:36 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pestphp/pest@1af74a215c (2026-08-21). Data as JSON: /api/errors/4bc2e4610b548bea. Report an issue: GitHub.