webmozarts/strict-phpunit
Enforces strict PHPUnit configuration for PHP projects using the Webmozart standards. Helps catch risky tests, deprecated usage, and unintended behavior by turning on stricter PHPUnit settings and providing an easy way to apply and maintain them across projects.
Begin by installing the package via Composer (composer require --dev webmozarts/strict-phpunit) and updating your test base class to extend Webmozart\Strict\PhpUnit\StrictTestCase instead of PHPUnit\Framework\TestCase. Your first use case: comparing value objects or DTOs in unit tests where accidental type coercion (e.g., "0" vs 0) would hide critical bugs. Replace assertEquals() with assertStrictEquals() for direct object equality checks—this enforces identical types and values, catching mismatches early in development.
StrictTestCase only in high-value test classes (e.g., domain model tests, API DTO contracts), leaving broader functional/integration tests on standard TestCase.assertStrictEquals() for core domain comparisons and assertEquals() for brittle edge cases (e.g., timezone-sensitive timestamps). Use helper methods like assertEqualsIgnoringOrder() to retain loose assertions where safe.phpunit.xml’s beStrictAboutOutputDuringTests="true" and beStrictAboutTestsThatDoNotTestAnything="true"), which this package enforces by default—ensuring CI mirrors local behavior.assertStrictEquals() compares by spl_object_id—not structural equality. Ensure your value objects override __toString() or implement JsonSerializable/custom comparison methods, or compare scalar properties explicitly.assertEquals($expected, $actual) with objects may now fail (e.g., "123" ≠ 123). Fix gradually: isolate failing tests, upgrade assertions one suite at a time, and leverage IDE refactoring tools.@group non-strict and @requires strict annotations (if supported by your PHPUnit version), or override StrictTestCase methods to relax checks for known flaky scenarios (e.g., mock callbacks).assertStrictEquals() throws RuntimeException, check for unserializable objects (e.g., closures, PDO connections) or circular references—extract only needed properties for comparison.How can I help you explore Laravel packages today?