From 9aeb18aee0b24328aa212dec7e59a731d75c1f77 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 12 Oct 2025 04:18:47 +0700 Subject: [PATCH] Revert "Revert "Fix global require-dev phpunit 12 (#7475)" (#7476)" This reverts commit 08c953e98fd3a00e77caeefebb09daa4f5b9127f. --- scoper.php | 1 + src/Testing/PHPUnit/AbstractLazyTestCase.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index 73d00ecf873..e8893e4b34f 100644 --- a/scoper.php +++ b/scoper.php @@ -33,6 +33,7 @@ 'exclude-classes' => [ 'PHPUnit\Framework\Constraint\IsEqual', 'PHPUnit\Framework\TestCase', + 'PHPUnit\Runner\Version', 'PHPUnit\Framework\ExpectationFailedException', // native class on php 8.3+ diff --git a/src/Testing/PHPUnit/AbstractLazyTestCase.php b/src/Testing/PHPUnit/AbstractLazyTestCase.php index 720990bc0ac..f4236153043 100644 --- a/src/Testing/PHPUnit/AbstractLazyTestCase.php +++ b/src/Testing/PHPUnit/AbstractLazyTestCase.php @@ -5,6 +5,7 @@ namespace Rector\Testing\PHPUnit; use PHPUnit\Framework\TestCase; +use PHPUnit\Runner\Version; use Rector\Config\RectorConfig; use Rector\DependencyInjection\LazyContainerFactory; @@ -63,7 +64,12 @@ private function includePreloadFilesAndScoperAutoload(): void { if (file_exists(__DIR__ . '/../../../preload.php')) { if (file_exists(__DIR__ . '/../../../vendor')) { - require_once __DIR__ . '/../../../preload.php'; + /** + * On PHPUnit 12+, when classmap autoloaded, it means preload already loaded early + */ + if (! class_exists(Version::class, true) || (int) Version::id() < 12) { + require_once __DIR__ . '/../../../preload.php'; + } // test case in rector split package } elseif (file_exists(__DIR__ . '/../../../../../../vendor')) { require_once __DIR__ . '/../../../preload-split-package.php';