diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index dfc5b0e63728..0e8c7cc12314 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -239,3 +239,11 @@ jobs:
mkdir -p /opt/php/lib
echo memory_limit=-1 > /opt/php/lib/php.ini
./build/php/bin/php ./phpunit --colors=always src/Symfony/Component/Process
+
+ - name: Run PhpUnitBridge tests with PHPUnit 11
+ if: '! matrix.mode'
+ run: |
+ ./phpunit src/Symfony/Bridge/PhpUnit
+ env:
+ SYMFONY_PHPUNIT_VERSION: '11.3'
+ SYMFONY_DEPRECATIONS_HELPER: 'disabled'
diff --git a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md
index a2dc7bd6706e..3c747025792f 100644
--- a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md
+++ b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md
@@ -4,6 +4,7 @@ CHANGELOG
7.2
---
+ * Add a PHPUnit extension that registers the clock mock and DNS mock and the `DebugClassLoader` from the ErrorHandler component if present
* Add `ExpectUserDeprecationMessageTrait` with a polyfill of PHPUnit's `expectUserDeprecationMessage()`
* Use `total` for asserting deprecation count when a group is not defined
diff --git a/src/Symfony/Bridge/PhpUnit/Extension/DisableClockMockSubscriber.php b/src/Symfony/Bridge/PhpUnit/Extension/DisableClockMockSubscriber.php
new file mode 100644
index 000000000000..885e6ea585e5
--- /dev/null
+++ b/src/Symfony/Bridge/PhpUnit/Extension/DisableClockMockSubscriber.php
@@ -0,0 +1,39 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\PhpUnit\Extension;
+
+use PHPUnit\Event\Code\TestMethod;
+use PHPUnit\Event\Test\Finished;
+use PHPUnit\Event\Test\FinishedSubscriber;
+use PHPUnit\Metadata\Group;
+use Symfony\Bridge\PhpUnit\ClockMock;
+
+/**
+ * @internal
+ */
+class DisableClockMockSubscriber implements FinishedSubscriber
+{
+ public function notify(Finished $event): void
+ {
+ $test = $event->test();
+
+ if (!$test instanceof TestMethod) {
+ return;
+ }
+
+ foreach ($test->metadata() as $metadata) {
+ if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) {
+ ClockMock::withClockMock(false);
+ }
+ }
+ }
+}
diff --git a/src/Symfony/Bridge/PhpUnit/Extension/DisableDnsMockSubscriber.php b/src/Symfony/Bridge/PhpUnit/Extension/DisableDnsMockSubscriber.php
new file mode 100644
index 000000000000..fc3e754d140d
--- /dev/null
+++ b/src/Symfony/Bridge/PhpUnit/Extension/DisableDnsMockSubscriber.php
@@ -0,0 +1,39 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\PhpUnit\Extension;
+
+use PHPUnit\Event\Code\TestMethod;
+use PHPUnit\Event\Test\Finished;
+use PHPUnit\Event\Test\FinishedSubscriber;
+use PHPUnit\Metadata\Group;
+use Symfony\Bridge\PhpUnit\DnsMock;
+
+/**
+ * @internal
+ */
+class DisableDnsMockSubscriber implements FinishedSubscriber
+{
+ public function notify(Finished $event): void
+ {
+ $test = $event->test();
+
+ if (!$test instanceof TestMethod) {
+ return;
+ }
+
+ foreach ($test->metadata() as $metadata) {
+ if ($metadata instanceof Group && 'dns-sensitive' === $metadata->groupName()) {
+ DnsMock::withMockedHosts([]);
+ }
+ }
+ }
+}
diff --git a/src/Symfony/Bridge/PhpUnit/Extension/EnableClockMockSubscriber.php b/src/Symfony/Bridge/PhpUnit/Extension/EnableClockMockSubscriber.php
new file mode 100644
index 000000000000..c10c5dcd18cd
--- /dev/null
+++ b/src/Symfony/Bridge/PhpUnit/Extension/EnableClockMockSubscriber.php
@@ -0,0 +1,39 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\PhpUnit\Extension;
+
+use PHPUnit\Event\Code\TestMethod;
+use PHPUnit\Event\Test\PreparationStarted;
+use PHPUnit\Event\Test\PreparationStartedSubscriber;
+use PHPUnit\Metadata\Group;
+use Symfony\Bridge\PhpUnit\ClockMock;
+
+/**
+ * @internal
+ */
+class EnableClockMockSubscriber implements PreparationStartedSubscriber
+{
+ public function notify(PreparationStarted $event): void
+ {
+ $test = $event->test();
+
+ if (!$test instanceof TestMethod) {
+ return;
+ }
+
+ foreach ($test->metadata() as $metadata) {
+ if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) {
+ ClockMock::withClockMock(true);
+ }
+ }
+ }
+}
diff --git a/src/Symfony/Bridge/PhpUnit/Extension/RegisterClockMockSubscriber.php b/src/Symfony/Bridge/PhpUnit/Extension/RegisterClockMockSubscriber.php
new file mode 100644
index 000000000000..e2955fe6003e
--- /dev/null
+++ b/src/Symfony/Bridge/PhpUnit/Extension/RegisterClockMockSubscriber.php
@@ -0,0 +1,39 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\PhpUnit\Extension;
+
+use PHPUnit\Event\Code\TestMethod;
+use PHPUnit\Event\TestSuite\Loaded;
+use PHPUnit\Event\TestSuite\LoadedSubscriber;
+use PHPUnit\Metadata\Group;
+use Symfony\Bridge\PhpUnit\ClockMock;
+
+/**
+ * @internal
+ */
+class RegisterClockMockSubscriber implements LoadedSubscriber
+{
+ public function notify(Loaded $event): void
+ {
+ foreach ($event->testSuite()->tests() as $test) {
+ if (!$test instanceof TestMethod) {
+ continue;
+ }
+
+ foreach ($test->metadata() as $metadata) {
+ if ($metadata instanceof Group && 'time-sensitive' === $metadata->groupName()) {
+ ClockMock::register($test->className());
+ }
+ }
+ }
+ }
+}
diff --git a/src/Symfony/Bridge/PhpUnit/Extension/RegisterDnsMockSubscriber.php b/src/Symfony/Bridge/PhpUnit/Extension/RegisterDnsMockSubscriber.php
new file mode 100644
index 000000000000..81382d5e13b4
--- /dev/null
+++ b/src/Symfony/Bridge/PhpUnit/Extension/RegisterDnsMockSubscriber.php
@@ -0,0 +1,39 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\PhpUnit\Extension;
+
+use PHPUnit\Event\Code\TestMethod;
+use PHPUnit\Event\TestSuite\Loaded;
+use PHPUnit\Event\TestSuite\LoadedSubscriber;
+use PHPUnit\Metadata\Group;
+use Symfony\Bridge\PhpUnit\DnsMock;
+
+/**
+ * @internal
+ */
+class RegisterDnsMockSubscriber implements LoadedSubscriber
+{
+ public function notify(Loaded $event): void
+ {
+ foreach ($event->testSuite()->tests() as $test) {
+ if (!$test instanceof TestMethod) {
+ continue;
+ }
+
+ foreach ($test->metadata() as $metadata) {
+ if ($metadata instanceof Group && 'dns-sensitive' === $metadata->groupName()) {
+ DnsMock::register($test->className());
+ }
+ }
+ }
+ }
+}
diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php b/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php
new file mode 100644
index 000000000000..1df4f2065890
--- /dev/null
+++ b/src/Symfony/Bridge/PhpUnit/SymfonyExtension.php
@@ -0,0 +1,52 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bridge\PhpUnit;
+
+use PHPUnit\Runner\Extension\Extension;
+use PHPUnit\Runner\Extension\Facade;
+use PHPUnit\Runner\Extension\ParameterCollection;
+use PHPUnit\TextUI\Configuration\Configuration;
+use Symfony\Bridge\PhpUnit\Extension\DisableClockMockSubscriber;
+use Symfony\Bridge\PhpUnit\Extension\DisableDnsMockSubscriber;
+use Symfony\Bridge\PhpUnit\Extension\EnableClockMockSubscriber;
+use Symfony\Bridge\PhpUnit\Extension\RegisterClockMockSubscriber;
+use Symfony\Bridge\PhpUnit\Extension\RegisterDnsMockSubscriber;
+use Symfony\Component\ErrorHandler\DebugClassLoader;
+
+class SymfonyExtension implements Extension
+{
+ public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
+ {
+ if (class_exists(DebugClassLoader::class)) {
+ DebugClassLoader::enable();
+ }
+
+ if ($parameters->has('clock-mock-namespaces')) {
+ foreach (explode(',', $parameters->get('clock-mock-namespaces')) as $namespace) {
+ ClockMock::register($namespace.'\DummyClass');
+ }
+ }
+
+ $facade->registerSubscriber(new RegisterClockMockSubscriber());
+ $facade->registerSubscriber(new EnableClockMockSubscriber());
+ $facade->registerSubscriber(new DisableClockMockSubscriber());
+
+ if ($parameters->has('dns-mock-namespaces')) {
+ foreach (explode(',', $parameters->get('dns-mock-namespaces')) as $namespace) {
+ DnsMock::register($namespace.'\DummyClass');
+ }
+ }
+
+ $facade->registerSubscriber(new RegisterDnsMockSubscriber());
+ $facade->registerSubscriber(new DisableDnsMockSubscriber());
+ }
+}
diff --git a/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php b/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
index 22f3565fab44..99d4a4bcfcee 100644
--- a/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
+++ b/src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
@@ -13,6 +13,9 @@
use PHPUnit\Framework\TestCase;
+/**
+ * @requires PHPUnit < 10
+ */
class CoverageListenerTest extends TestCase
{
public function test()
diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php
index 5bbf714dd2cc..7eec02954c1c 100644
--- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php
+++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/ConfigurationTest.php
@@ -463,6 +463,9 @@ public function testExistingBaselineAndGeneration()
$this->assertEquals(json_encode($expected, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES), file_get_contents($filename));
}
+ /**
+ * @requires PHPUnit < 10
+ */
public function testBaselineGenerationWithDeprecationTriggeredByDebugClassLoader()
{
$filename = $this->createFile();
diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/log_file.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/log_file.phpt
index 0a64337d0808..fe14db7c53da 100644
--- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/log_file.phpt
+++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/log_file.phpt
@@ -1,5 +1,7 @@
--TEST--
Test DeprecationErrorHandler with log file
+--SKIPIF--
+=')) die('Skipping on PHPUnit 10+');
--FILE--
+
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: