Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Concerns/Testable.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ public static function tearDownAfterClass(): void
$afterAll = ChainableClosure::boundStatically(self::$__afterAll, $afterAll);
}

call_user_func(Closure::bind($afterAll, null, self::class));
try {
call_user_func(Closure::bind($afterAll, null, self::class));
} finally {
self::flush();
}

parent::tearDownAfterClass();
}
Expand Down Expand Up @@ -371,9 +375,6 @@ protected function tearDown(...$arguments): void
parent::tearDown();

TestSuite::getInstance()->test = null;

$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
$method->tearDown($this);
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/Factories/TestCaseMethodFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ public function setUp(TestCase $concrete): void
$this->factoryProxies->proxy($concrete);
}

/**
* Flushes the test case.
*/
public function tearDown(TestCase $concrete): void
{
$concrete::flush(); // @phpstan-ignore-line
}

/**
* Creates the test's closure.
*/
Expand Down
31 changes: 31 additions & 0 deletions tests/Hooks/AfterAllTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use function PHPUnit\Framework\assertSame;

$_SERVER['globalHook']->calls->afterAllInFile = 0;
$_SERVER['globalHook']->calls->afterAllTestsRan = 0;

pest()->afterAll(function () {
$_SERVER['globalHook']->calls->afterAllInFile++;
});

it('does not get called before all tests 1', function () {
$_SERVER['globalHook']->calls->afterAllTestsRan++;
expect($_SERVER['globalHook']->calls->afterAllInFile)->toBe(0);
})->repeat(2);

it('does not get called before all tests 2', function () {
$_SERVER['globalHook']->calls->afterAllTestsRan++;
expect($_SERVER['globalHook']->calls->afterAllInFile)->toBe(0);
});

register_shutdown_function(function () {
// Under --parallel, Pest also evaluates this file in the parent process to
// build the suite; the tests (and therefore afterAll) only run in the worker.
// Skip the assertion in any process where no test of this file actually ran.
if ($_SERVER['globalHook']->calls->afterAllTestsRan === 0) {
return;
}

assertSame(1, $_SERVER['globalHook']->calls->afterAllInFile, 'Expected the [pest()->afterAll()] hook to have been called exactly once.');
});