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.
symfony/http-foundation or symfony/routing), this package could be partially leveraged for those specific areas.withConsecutive for mocks, time manipulation, and image/PDF assertions). Laravel's built-in PHPUnit integration could absorb these utilities where applicable, but not all features are Laravel-native.ClockTestTrait, ImageTestTrait) are self-contained, allowing selective adoption. However, Symfony-specific traits (e.g., AbstractControllerTestCase) would require abstraction layers to work in Laravel.PdfTestTrait (PR #42). This is an additive, non-breaking change that broadens the PDF assertion pathway to a second library. Architecturally it lowers coupling to any single PDF engine, improving fit for Laravel apps that use tecnickcom/tc-lib-pdf instead of classic TCPDF.ResponseAssertions, AbstractConstraintValidatorTestCase) could be adapted with minimal effort.withConsecutive, ClockTestTrait, and image/PDF assertions are language-agnostic and could be directly integrated into Laravel's test suite.HttpTests, DatabaseTransactions) is not directly compatible with Symfony-centric utilities. A wrapper layer would be needed to bridge gaps.tc-lib-pdf package (a common successor to legacy TCPDF in newer Laravel PDF-generation stacks) can now adopt PdfTestTrait without swapping their PDF engine. This meaningfully raises feasibility for PDF-heavy Laravel apps, though the underlying Imagick/Ghostscript requirement likely persists for rendering-based assertions.ImageTestTrait and PdfTestTrait require Imagick (with Ghostscript). As of v1.14.0, PDF support covers both TCPDF and TcLibPdf, so the PDF-library lock-in risk is reduced, but the rendering toolchain (Imagick/Ghostscript) remains the primary infrastructure constraint.ClockTestTrait) modify global state, which could interfere with Laravel's test helpers (e.g., RefreshDatabase, PreserveFreshModels).PdfTestTrait who may need to verify the new TcLibPdf code path behaves consistently with the TCPDF path.symfony/http-foundation for responses) justify integration?tecnickcom/tc-lib-pdf or legacy TCPDF? The new release makes PdfTestTrait viable for the former, which may change the cost/benefit calculus.laravel-shift/blueprint, spatie/laravel-test-factories) that could achieve similar goals with less risk?| Package Feature | Laravel Stack Fit | Workaround Needed? |
|---|---|---|
withConsecutive |
✅ Directly usable in PHPUnit tests. | No |
ClockTestTrait |
✅ Useful for time-sensitive tests (e.g., queues, scheduled jobs). | No |
ImageTestTrait |
⚠️ Requires Imagick; useful for image-processing apps (e.g., interventions/image). | Yes (Docker/CI setup) |
PdfTestTrait (TCPDF) |
⚠️ Requires Imagick; niche use case (e.g., PDF generation libraries). | Yes (dependency management) |
PdfTestTrait (TcLibPdf) — new |
✅ Improved fit for apps on tecnickcom/tc-lib-pdf; no engine swap required. |
Reduced (Imagick/Ghostscript still likely needed) |
Symfony Controller Tests |
❌ Incompatible (Symfony-specific). | Yes (abstraction layer or avoid) |
AbstractConstraintValidatorTestCase |
❌ Symfony Validator only. | Yes (use Laravel's Assert or custom validators) |
ResponseAssertions |
⚠️ Laravel uses HttpTestResponse; partial overlap (e.g., status codes). |
Yes (wrapper trait for Laravel responses) |
Phase 1: Low-Risk Adoption
withConsecutive and ClockTestTrait via Composer.Phase 2: Symfony Interop & PDF Modernization
laravel-shift/blueprint).trait LaravelResponseAssertions {
use ResponseAssertions;
protected function adaptResponse($response) {
return new SymfonyResponse($response->content(), $response->status());
}
}
ImageTestTrait if the app generates images (e.g., with intervention/image).PdfTestTrait — with v1.14.0, this is now viable for both TCPDF and TcLibPdf stacks. Apps that already migrated to tecnickcom/tc-lib-pdf no longer need to downgrade or dual-maintain a PDF engine.Phase 3: Advanced Features
PdfTestTrait only where PDF output validation is a hard requirement; pick the code path matching your engine (TCPDF vs. TcLibPdf).AbstractControllerTestCase) unless the app is hybrid.phpunit/phpunit@^10.0 in composer.json and update test classes incrementally.symfony/form, symfony/validator). Mitigation:
replace in composer.json to avoid conflicts:
"replace": {
"symfony/form": "v6.4.0",
"symfony/validator": "v6.4.0"
}
ClockTestTrait may conflict with Laravel's RefreshDatabase. Mitigation: Run time-sensitive tests in separate test classes.composer.json:
"require-dev": {
"digitalrevolution/phpunit-extensions": "^1.14"
}
withConsecutive and ClockTestTrait in existing test suites.ImageTestTrait for image-related tests.PdfTestTrait only after confirming the engine-specific path (TCPDF vs. TcLibPdf).PHPUNIT_EXTENSIONS_IMAGE_DIFF_OUTPUT_PATH for image diffs.ClockTestTrait) could break test isolation.withConsecutive or ClockTestTrait.PdfTestTrait without re-platforming their PDF generation, reducing onboarding cost for the most niche feature.Recommendation: Adopt v1.14.0 — it is a non-breaking feature release that improves optionality. Continue with the phased plan; elevate PdfTestTrait from "niche/conditional" to "viable" for any team on tecnickcom/tc-lib-pdf, and re-verify the PDF assertion path in CI before broad rollout.
How can I help you explore Laravel packages today?