Sebastian Bergmann, the creator of PHPUnit, reflects on why he stopped using setUp() and tearDown() methods for managing test fixtures. Instead of storing test state in object properties via setUp(), he now uses private factory methods called directly within each test. This approach avoids unnecessary setup for tests that don't need it, prevents inheritance-related bugs from forgetting parent::setUp() calls, and allows PHP's garbage collector to clean up objects immediately after each test rather than at the end of the process.

4m read timeFrom phpunit.expert
Post cover image
Table of contents
Test Fixture with setUp()Test Fixture without setUp()

Sort: