Files
pest/tests/Visual/AfterAll.php
T
Sonali dudhia 9aed110ba0 fix: run pest()->afterAll() hooks by flushing statics after tearDownAfterClass() (#1753)
* fix: run `pest()->afterAll()` hooks by flushing statics after `tearDownAfterClass()`

Fixes #1694

Testable::tearDown()'s finally block flushed the afterAll static after
every test via TestCaseMethodFactory::tearDown(), so by the time PHPUnit
called tearDownAfterClass() (which runs after the last test's tearDown())
the hook had already been nulled out. The per-test flush was redundant:
TestCaseMethodFactory::setUp() already flushes statics before re-applying
proxies for the next test. Move the flush into tearDownAfterClass()'s
finally block instead, so it happens after the hook actually runs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* test: assert `afterAll` hooks run via isolated fixture suite

Runs a fixture suite in a subprocess and asserts both the
`pest()->afterAll()` and file-level `afterAll()` hooks ran once,
in order. Fails on unpatched 5.x (only `afterAll` is recorded).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style: remove comment from afterAll hook test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix afterAll test style and refresh snapshots

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
2026-11-14 15:13:25 +05:30

32 lines
844 B
PHP

<?php
declare(strict_types=1);
use Symfony\Component\Process\Process;
test('afterAll hooks run once after all tests of the file', function (): void {
$marker = tempnam(sys_get_temp_dir(), 'pest-after-all-');
$process = new Process([
'php',
'bin/pest',
'tests/Fixtures/Suites/AfterAll',
'--test-directory=tests/Fixtures/Suites/AfterAll',
'--colors=never',
], dirname(__DIR__, 2), [
'COLLISION_PRINTER' => 'DefaultPrinter',
'COLLISION_IGNORE_DURATION' => 'true',
'PAO_DISABLE' => '1',
'PEST_AFTER_ALL_MARKER' => $marker,
]);
$process->run();
$calls = file_get_contents($marker);
unlink($marker);
expect($process->getExitCode())->toBe(0)
->and($calls)->toBe('pest()->afterAll'.PHP_EOL.'afterAll'.PHP_EOL);
})->skipOnWindows();