From 6acc4e62308a72a6e50ed51d6ce095ac52cdd3d1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 8 Oct 2025 20:11:31 +0700 Subject: [PATCH 1/5] [Scoped] Load early preload.php on scoped bootstrap.php on phpunit running --- build/target-repository/bootstrap.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build/target-repository/bootstrap.php b/build/target-repository/bootstrap.php index 2e46abf997c..244864aed67 100644 --- a/build/target-repository/bootstrap.php +++ b/build/target-repository/bootstrap.php @@ -2,6 +2,18 @@ declare(strict_types = 1); +/** + * The preload.php contains 2 dependencies + * - phpstan/phpdoc-parser + * - nikic/php-parser + * + * They need to be loaded early to avoid conflict version between rector prefixed vendor and Project vendor + * For example, a project may use PHPParser v4, while Rector uses v5, that will error as class or logic are different. + */ +if (defined('PHPUNIT_COMPOSER_INSTALL')) { + require_once __DIR__ . '/preload.php'; +} + // inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php spl_autoload_register(function (string $class): void { static $composerAutoloader; From 7c2760f608dce158aafa482fa8a13599f811ca74 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 8 Oct 2025 20:21:27 +0700 Subject: [PATCH 2/5] ensure verify Node interface exists --- build/target-repository/bootstrap.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/build/target-repository/bootstrap.php b/build/target-repository/bootstrap.php index 244864aed67..4605de81ffb 100644 --- a/build/target-repository/bootstrap.php +++ b/build/target-repository/bootstrap.php @@ -2,6 +2,8 @@ declare(strict_types = 1); +use PHPParser\Node; + /** * The preload.php contains 2 dependencies * - phpstan/phpdoc-parser @@ -10,7 +12,13 @@ * They need to be loaded early to avoid conflict version between rector prefixed vendor and Project vendor * For example, a project may use PHPParser v4, while Rector uses v5, that will error as class or logic are different. */ -if (defined('PHPUNIT_COMPOSER_INSTALL')) { +if ( + // verify PHPUnit is running + defined('PHPUNIT_COMPOSER_INSTALL') + + // no need to preload if Node interface exists + && ! interface_exists(Node::class, false) +) { require_once __DIR__ . '/preload.php'; } From d0fbaf9c34213be8846353a7e962bf89bd7b78c8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 8 Oct 2025 20:37:34 +0700 Subject: [PATCH 3/5] handling on phpunit 12.+ only --- build/target-repository/bootstrap.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build/target-repository/bootstrap.php b/build/target-repository/bootstrap.php index 4605de81ffb..64d1180a2a3 100644 --- a/build/target-repository/bootstrap.php +++ b/build/target-repository/bootstrap.php @@ -1,8 +1,9 @@ = 12 ) { require_once __DIR__ . '/preload.php'; } From cd6f41f662ad92c7ba24d0276d6026434e4be24e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 8 Oct 2025 21:32:51 +0700 Subject: [PATCH 4/5] final touch: better note example use of phpstan/phpdoc-parser that conflict can be early --- build/target-repository/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/target-repository/bootstrap.php b/build/target-repository/bootstrap.php index 64d1180a2a3..1f9ed93f76a 100644 --- a/build/target-repository/bootstrap.php +++ b/build/target-repository/bootstrap.php @@ -11,7 +11,7 @@ * - nikic/php-parser * * They need to be loaded early to avoid conflict version between rector prefixed vendor and Project vendor - * For example, a project may use PHPParser v4, while Rector uses v5, that will error as class or logic are different. + * For example, a project may use phpstan/phpdoc-parser v1, while phpstan/phpdoc-parser uses v2, that will error as class or logic are different. */ if ( // verify PHPUnit is running From b8a1da7bc640276d57b506290e0241b5238c77c3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 8 Oct 2025 21:33:32 +0700 Subject: [PATCH 5/5] final touch: better note example use of phpstan/phpdoc-parser that conflict can be early --- build/target-repository/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/target-repository/bootstrap.php b/build/target-repository/bootstrap.php index 1f9ed93f76a..3dbb6e139eb 100644 --- a/build/target-repository/bootstrap.php +++ b/build/target-repository/bootstrap.php @@ -11,7 +11,7 @@ * - nikic/php-parser * * They need to be loaded early to avoid conflict version between rector prefixed vendor and Project vendor - * For example, a project may use phpstan/phpdoc-parser v1, while phpstan/phpdoc-parser uses v2, that will error as class or logic are different. + * For example, a project may use phpstan/phpdoc-parser v1, while rector uses phpstan/phpdoc-parser uses v2, that will error as class or logic are different. */ if ( // verify PHPUnit is running