symfony/phpunit-bridge
Symfony PHPUnit Bridge adds utilities around PHPUnit, with a focus on managing and asserting deprecation notices for smoother upgrades. It helps track, filter, and report deprecations during test runs, making CI output cleaner and migrations safer.
phpunit.xml or phpunit.php configuration) without requiring architectural changes.phpunit setup. No custom bootstrapping or service provider modifications are required.@group) and attribute-based (#[Group]) PHPUnit configurations, ensuring compatibility with Laravel’s evolving test syntax (PHPUnit 9.x+).| Risk | Mitigation Strategy | Severity |
|---|---|---|
| PHPUnit Version Conflicts | Test locally with Laravel’s PHPUnit version (e.g., phpunit/phpunit:^9.5) before CI integration. |
Low |
| Deprecation Overload | Start with opt-in deprecation checks (e.g., ExpectUserDeprecationMessageTrait) before enforcing strict mode. |
Medium |
| Test Suite Slowdown | Benchmark impact on test execution time; cache deprecation checks if performance is critical. | Low |
| Custom Test Listeners | Audit existing listeners for conflicts with the bridge’s TestCase patching. |
Medium |
| PHP 8.4+ Compatibility | Verify ClockMock/DnsMock features work with Laravel’s PHP version (e.g., PHP 8.2+). |
Low |
ClockMock/DnsMock features require PHPUnit 10+.@expectedDeprecation) that need migration?phpunit --debug.)ClockMock/DnsMock?phpunit.xml configuration.tests/TestCase base class.phpunit command.v7.x of the bridge (e.g., symfony/phpunit-bridge:^7.4).v8.x (e.g., symfony/phpunit-bridge:^8.0) for ClockMock/DnsMock.symfony/http-client), the bridge’s ClockMock can mock time-dependent logic in tests.Http facade (which uses Symfony’s HttpClient) can leverage these mocks for testing.composer require --dev symfony/phpunit-bridge "^7.4" # For PHPUnit 9.x
# OR
composer require --dev symfony/phpunit-bridge "^8.0" # For PHPUnit 10.x
phpunit.xml to enable deprecation checks:
<phpunit>
<extensions>
<extension class="Symfony\Bridge\PhpUnit\DeprecationErrorListener"/>
</extensions>
</phpunit>
ExpectUserDeprecationMessageTrait in critical tests:
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
class DeprecationTest extends TestCase
{
use ExpectUserDeprecationMessageTrait;
public function testDeprecatedFeature()
{
$this->expectUserDeprecationMessage('Deprecated feature used');
// Test code that triggers deprecation.
}
}
.github/workflows/tests.yml:
- name: Run tests
run: php artisan test -- --fail-on-deprecation
ExpectUserDeprecationMessageTrait for new tests.| Component | Compatibility | Notes |
|---|---|---|
| Laravel 9/10 | ✅ Full compatibility (PHPUnit 9.x/10.x) | Use ^7.4 or ^8.0 of the bridge. |
| PestPHP | ⚠️ Partial (PHPUnit under the hood) | May require custom setup. |
| Custom Test Listeners | ⚠️ Potential conflicts with TestCase patching |
Audit existing listeners. |
| PHP 8.2+ | ✅ Supported (PHP 8.4+ for ClockMock features) |
Check Laravel’s PHP version support. |
| Symfony Components | ✅ Enhanced (e.g., ClockMock for HTTP Client tests) |
Beneficial if using Symfony packages. |
php artisan test -- --debug to identify current deprecation warnings.^8.0).ExpectUserDeprecationMessageTrait and @expectedDeprecation.^8.0 when moving to PHPUnit 10).Illuminate\Support\Facades\Route::controller()).TestCase patching failures) are documented in Symfony’s docs.How can I help you explore Laravel packages today?