digitalrevolution/phpunit-extensions
PHPUnit extensions offering utility classes for easier unit testing: a withConsecutive replacement for PHPUnit 10 migration, plus Symfony AbstractControllerTestCase and ConstraintValidator test case helpers for mocking users, forms, violations, and more.
Accelerate Test-Driven Development (TDD) for Symfony/Laravel:
Adopting this package enables rapid development of Symfony-based (or Laravel-compatible) applications by reducing boilerplate in unit/integration tests. The AbstractControllerTestCase and AbstractConstraintValidatorTestCase abstract away repetitive mocking of Symfony services (e.g., Security, Form, Validator), cutting test setup time by 30–50% for teams heavily using Symfony components.
Future-Proof Migration Paths:
The withConsecutive compatibility layer ensures zero-breaking changes when upgrading PHPUnit (e.g., from v9 to v10+), aligning with Laravel’s long-term support (LTS) roadmap. This avoids costly refactoring during major PHPUnit/Symfony version bumps.
Build vs. Buy for Test Utilities: Buy: This package is a low-risk, high-reward alternative to building custom test utilities. It’s battle-tested by 50+ developers at 123inkt (a Digital Revolution company) and covers niche but critical use cases (e.g., PDF/image diffing, time manipulation, PDF-library abstraction). Build: Only consider custom solutions if your stack requires domain-specific assertions (e.g., proprietary validation rules) not covered here.
Reduced Vendor Lock-In at the Test Layer (new in v1.14.0):
PdfTestTrait now supports TcLibPdf alongside the previously supported PDF engine(s). This matters as a product decision, not just a testing convenience: PDF generation libraries are a common swap-out point (licensing costs, rendering fidelity, HTML-to-PDF vendor changes, PHP version support). Because visual regression coverage no longer forces a specific PDF engine, a future "replace our PDF library" initiative can be evaluated on cost/output quality rather than blocked by "we'd lose our regression tests." It also de-risks incremental engine migrations, since old and new output can be diffed under the same trait.
Key Use Cases:
Security, Form, and Router interactions without manual stubbing.ConstraintValidators with fluent assertion chaining (e.g., expectBuildViolation()->expectAtPath()).ClockTestTrait (useful for scheduled jobs or time-based logic).ImageTestTrait/PdfTestTrait; PDF rendering is supported across multiple engines, now including TcLibPdf (v1.14.0).ResponseAssertions (e.g., assertJsonResponse(200, ['key' => 'value'])).Adopt if:
PdfTestTrait, so TcLibPdf-based document pipelines can adopt without upstream work or a custom trait.withConsecutive.Look elsewhere if:
phpunit/phpunit or mockery/mockery may suffice.For Executives:
"This package cuts test development time by 30–50% for Symfony/Laravel teams by eliminating repetitive mocking of core services like Security, Forms, and Validators. For example, testing a controller’s access control now requires one line ($this->expectDenyAccessUnlessGranted()) instead of manually stubbing the Security component. It also enables visual regression testing for PDFs/images (critical for compliance reports or marketing assets) without reinventing the wheel — and the latest release (v1.14.0) adds TcLibPdf support, so our PDF-vendor choice is no longer dictated by what our test tooling can verify. That keeps the door open on a future PDF engine switch if licensing or output quality changes. The MIT license and active maintenance (latest release: v1.14.0, additive and non-breaking) make it a low-risk, high-ROI choice to accelerate QA and reduce technical debt."
For Engineering: *"This gives us Symfony-specific superpowers in PHPUnit:
Security, Form, and Router interactions with fluent assertions (e.g., expectCreateForm()->expectSubmit()).expectBuildViolation()->expectAtPath() for complex constraints.ClockTestTrait (no more DateTime::createFromFormat hacks).ImageTestTrait/PdfTestTrait (generates diffs for CI debugging). v1.14.0 adds TcLibPdf to PdfTestTrait, so TcLibPdf-rendered documents are now covered — no private fork or bespoke trait needed.withConsecutive polyfill lets us upgrade without rewriting tests.Release status (v1.14.0): Purely additive single-PR change (PdfTestTrait + TcLibPdf). No breaking changes, no deprecations, no migration steps — a safe patch-level bump. If we're already on PdfTestTrait, upgrading is a no-op unless we adopt TcLibPdf.
Trade-offs:
Next Steps:
AbstractControllerTestCase) and measure setup time savings.Cost: Zero (MIT license). Risk: Low (used by 50+ devs at 123inkt; v1.14.0 is additive only)."*
How can I help you explore Laravel packages today?