From 957658da1c7139e698e31a7ad858c2e23cfb1a45 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 9 Oct 2025 16:58:24 +0700 Subject: [PATCH] [Alternative] Let preload.php require on PHPUnit < 12 on AbstractLazyTestCase --- phpstan.neon | 2 ++ scoper.php | 1 + src/Testing/PHPUnit/AbstractLazyTestCase.php | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 756eba937d9..b37ddd6f34b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -150,6 +150,8 @@ parameters: # for config class reflection - src/Bootstrap/ExtensionConfigResolver.php - src/Validation/RectorConfigValidator.php + # for phpunit version check + - src/Testing/PHPUnit/AbstractLazyTestCase.php # use of internal phpstan classes - 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..863cb314484 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,11 @@ private function includePreloadFilesAndScoperAutoload(): void { if (file_exists(__DIR__ . '/../../../preload.php')) { if (file_exists(__DIR__ . '/../../../vendor')) { - require_once __DIR__ . '/../../../preload.php'; + // this ensure to not load preload.php on phpunit >= 12 + if (! class_exists(Version::class) || (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';