[Bug]: AfterAll() hook not being called
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.7k
- Forks
- 538
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
What Happened
I am trying to use the AfterAll() global hook to reset fixture data in a file.
What I expected was that the data would be reset.
What happens is nothing; the closure I set in Pest.php is never called.
If I set a breakpoint on the closure it is never reached.
By contrast, the BeforeAll() (which I use to initialise the fixture data), BeforeEach() and AfterEach() global hooks work as expected and pause on breakpoints when set.
How to Reproduce
In Pest.php
pest()->in('Feature') ->extend(TestCase::class) ->beforeAll(function () { TestCase::beforeAll(); }) ->afterAll(function () { TestCase::afterAll(); }) ;
In TestCase.php
`
abstract class TestCase extends BaseTestCase {
public static function afterAll(): void
{
// clear fixture - set a breakpoint here and it will not be hit
}
public static function beforeAll(): void
{
// initialise fixture - set a breakpoint here and it will be hit
}
}
`
Sample Repository
No response
Pest Version
pest: 4.7 & pest-plugin-browser: 4.3.1
PHP Version
8.5.3
Operation System
Linux
Notes
Looking in Testable::tearDownAfterClass() (I assuming this is the right place as the comment states that "This method is called after the last test of this Test Case is run."), $afterAll is an instance of Support/NullClosure.php; I kind of think it should be the closure I set in Pest.php.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Testable::tearDownAfterClass(), where the issue reports that $afterAll is a Support/NullClosure instead of the closure configured in Pest.php. Trace how the global afterAll hook is registered for the Feature group and compare it with the working beforeAll, beforeEach, and afterEach hooks. Done means the closure in TestCase.php is called after the last test and its breakpoint is reached.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100