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.
DateTimeInterface, generics, nullable unions) and Laravel’s typed properties, ensuring robust validation.AccessorPairAsserter trait. No database or service container modifications are needed.getAttribute()/setAttribute() methods (if manually implemented).rules() and authorize() interactions with accessors.ConstraintConfig allows excluding methods (e.g., skip setPassword() if it has custom logic) or overriding value providers (e.g., for complex objects like Collection or Carbon).setExcludedMethods().app() calls or dynamic property handling). Requires manual overrides or additional tests.User model with 50+ methods), consider selective adoption (e.g., only test critical DTOs).laravel/framework constraints.Feature vs. Unit tests)?getRouteKeyName()) that need exclusion or custom value providers?HasAttributes trait or Attribute macros?ConstraintConfig if Laravel introduces new accessor patterns (e.g., getFillable())?setFooAttribute() in favor of setAttribute()) be handled?phpunit.xml configurations (no changes needed beyond composer require).TestCase base class (extend or mix into existing test classes).spatie/laravel-data or custom DTOs for API responses.rules() interactions with accessors (e.g., setEmail() → getEmail()).toArray() reflects setter changes.UserCommand DTOs).UserResource with assertAccessorPairs().TestCase base class (opt-in via trait).setExcludedMethods() for edge cases).ConstraintConfig in a test helper class (e.g., tests/TestHelpers.php) for consistency.$config = (new ConstraintConfig())
->setExcludedMethods(['setPassword', 'setRememberToken'])
->setAssertPropertyDefaults(true);
__get()/__set() unless explicitly included.setValueProvider() for mocks.^9.5 for compatibility).composer.json (dev dependency).TestCase or create a base test class:
use DigitalRevolution\AccessorPairConstraint\AccessorPairAsserter;
abstract class BaseTestCase extends \Tests\TestCase
{
use AccessorPairAsserter;
}
assertAccessorPairs().boot()).--coverage to ensure 100% accessor coverage for DTOs.User model serialization).assertEquals($obj->getX(), $expected) tests.ConstraintConfig may need updates for Laravel-specific changes (e.g., new accessor methods).excludedMethods or valueProvider callbacks as Laravel evolves.assertAccessorPairs().setCreatedAt()).valueProvider).How can I help you explore Laravel packages today?