digitalrevolution/accessorpair-constraint
PHPUnit helper to automatically test and cover getters/setters (and constructor-to-getter pairs) on data classes. Add the AccessorPairAsserter trait and call assertAccessorPairs() to validate accessor pairs, optional default/initial value checks.
Adopt When:
Look Elsewhere If:
__get(), __set()) or lack explicit getters/setters."This package automates 80% of the repetitive tests for data classes—like DTOs or Laravel models—saving our team hours per sprint on manual test writing. By ensuring every getter/setter pair is validated, we reduce production bugs related to data corruption or type mismatches. It’s a low-risk, high-reward investment for quality, with minimal maintenance overhead. Think of it as ‘CI/CD for your data layer.’"
Key Outcomes:
*"The AccessorPair Constraint lets you test all getters/setters in a single line of code, cutting boilerplate tests for data classes. It handles edge cases like:
DateTimeInterface).Why Use It?
Example:
// Replace 20+ manual tests with:
$this->assertAccessorPairs(UserDto::class);
Trade-off: Minimal learning curve; ideal for teams already using PHPUnit. Avoid if your data classes are highly dynamic or require bespoke validation."*
For Developers:
How can I help you explore Laravel packages today?