pestphp/pest · error · AfterAllAlreadyExist

The [afterAll] hook is already defined in [%s]. Each test fi

Error message

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

What it means

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

Source

Thrown at src/Repositories/AfterAllRepository.php:34

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

    public function each(callable $each): void
    {
        foreach ($this->state as $filename => $closure) {
            $each($filename, $closure);
        }
    }

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

        if (array_key_exists($filename, $this->state)) {
            throw new AfterAllAlreadyExist($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/AfterAllRepository.php:34 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/40598dc65982f6d2. Report an issue: GitHub.