Skip to content

Commit 957658d

Browse files
committed
[Alternative] Let preload.php require on PHPUnit < 12 on AbstractLazyTestCase
1 parent 7ccb174 commit 957658d

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ parameters:
150150
# for config class reflection
151151
- src/Bootstrap/ExtensionConfigResolver.php
152152
- src/Validation/RectorConfigValidator.php
153+
# for phpunit version check
154+
- src/Testing/PHPUnit/AbstractLazyTestCase.php
153155

154156
# use of internal phpstan classes
155157
-

scoper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'exclude-classes' => [
3434
'PHPUnit\Framework\Constraint\IsEqual',
3535
'PHPUnit\Framework\TestCase',
36+
'PHPUnit\Runner\Version',
3637
'PHPUnit\Framework\ExpectationFailedException',
3738

3839
// native class on php 8.3+

src/Testing/PHPUnit/AbstractLazyTestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Rector\Testing\PHPUnit;
66

77
use PHPUnit\Framework\TestCase;
8+
use PHPUnit\Runner\Version;
89
use Rector\Config\RectorConfig;
910
use Rector\DependencyInjection\LazyContainerFactory;
1011

@@ -63,7 +64,11 @@ private function includePreloadFilesAndScoperAutoload(): void
6364
{
6465
if (file_exists(__DIR__ . '/../../../preload.php')) {
6566
if (file_exists(__DIR__ . '/../../../vendor')) {
66-
require_once __DIR__ . '/../../../preload.php';
67+
// this ensure to not load preload.php on phpunit >= 12
68+
if (! class_exists(Version::class) || (int) Version::id() < 12) {
69+
require_once __DIR__ . '/../../../preload.php';
70+
}
71+
6772
// test case in rector split package
6873
} elseif (file_exists(__DIR__ . '/../../../../../../vendor')) {
6974
require_once __DIR__ . '/../../../preload-split-package.php';

0 commit comments

Comments
 (0)