From 6cdbe878a605cde09b253f811acee39217441f5a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 22:00:56 +0700 Subject: [PATCH] Fix global require-dev phpunit 12 --- 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';