From ed40c5acb7cce2849c6854bb30851c1c3be02ed1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 05:56:51 +0700 Subject: [PATCH 1/2] Handle crash redeclare isPHPStanTestPreloaded() method --- build/build-preload.php | 14 ++++++++------ preload-split-package.php | 14 ++++++++------ preload.php | 14 ++++++++------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/build/build-preload.php b/build/build-preload.php index de87adabbbc..26204dae850 100755 --- a/build/build-preload.php +++ b/build/build-preload.php @@ -65,13 +65,15 @@ final class PreloadBuilder return; } -function isPHPStanTestPreloaded(): bool -{ - if (! class_exists(PHPStanTestCase::class, false)) { - return false; - } +if (! function_exists('isPHPStanTestPreloaded')) { + function isPHPStanTestPreloaded(): bool + { + if (! class_exists(PHPStanTestCase::class, false)) { + return false; + } - return interface_exists(Node::class, false); + return interface_exists(Node::class, false); + } } CODE_SAMPLE; diff --git a/preload-split-package.php b/preload-split-package.php index da953d5a7e5..093d16b9f3b 100644 --- a/preload-split-package.php +++ b/preload-split-package.php @@ -16,13 +16,15 @@ return; } -function isPHPStanTestPreloaded(): bool -{ - if (! class_exists(PHPStanTestCase::class, false)) { - return false; - } +if (! function_exists('isPHPStanTestPreloaded')) { + function isPHPStanTestPreloaded(): bool + { + if (! class_exists(PHPStanTestCase::class, false)) { + return false; + } - return interface_exists(Node::class, false); + return interface_exists(Node::class, false); + } } require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node.php'; diff --git a/preload.php b/preload.php index cecb0b90b4c..807a3ed59d9 100644 --- a/preload.php +++ b/preload.php @@ -16,13 +16,15 @@ return; } -function isPHPStanTestPreloaded(): bool -{ - if (! class_exists(PHPStanTestCase::class, false)) { - return false; - } +if (! function_exists('isPHPStanTestPreloaded')) { + function isPHPStanTestPreloaded(): bool + { + if (! class_exists(PHPStanTestCase::class, false)) { + return false; + } - return interface_exists(Node::class, false); + return interface_exists(Node::class, false); + } } require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php'; From 232dcab3b1d38a33f00a2d76832fedcbc9cc5de8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 11 Oct 2025 06:03:41 +0700 Subject: [PATCH 2/2] define early --- build/build-preload.php | 14 +++++++------- preload-split-package.php | 14 +++++++------- preload.php | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build/build-preload.php b/build/build-preload.php index 26204dae850..99eac46ca48 100755 --- a/build/build-preload.php +++ b/build/build-preload.php @@ -58,13 +58,6 @@ final class PreloadBuilder return; } -// edge case during Rector tests case, happens when -// 1. phpstan autoload test case is triggered first, -// 2. all php-parser classes are loaded, -if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) { - return; -} - if (! function_exists('isPHPStanTestPreloaded')) { function isPHPStanTestPreloaded(): bool { @@ -75,6 +68,13 @@ function isPHPStanTestPreloaded(): bool return interface_exists(Node::class, false); } } + +// edge case during Rector tests case, happens when +// 1. phpstan autoload test case is triggered first, +// 2. all php-parser classes are loaded, +if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) { + return; +} CODE_SAMPLE; /** diff --git a/preload-split-package.php b/preload-split-package.php index 093d16b9f3b..6277792f51c 100644 --- a/preload-split-package.php +++ b/preload-split-package.php @@ -9,13 +9,6 @@ return; } -// edge case during Rector tests case, happens when -// 1. phpstan autoload test case is triggered first, -// 2. all php-parser classes are loaded, -if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) { - return; -} - if (! function_exists('isPHPStanTestPreloaded')) { function isPHPStanTestPreloaded(): bool { @@ -27,6 +20,13 @@ function isPHPStanTestPreloaded(): bool } } +// edge case during Rector tests case, happens when +// 1. phpstan autoload test case is triggered first, +// 2. all php-parser classes are loaded, +if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) { + return; +} + require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node.php'; require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php'; require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php'; diff --git a/preload.php b/preload.php index 807a3ed59d9..15a5592d77c 100644 --- a/preload.php +++ b/preload.php @@ -9,13 +9,6 @@ return; } -// edge case during Rector tests case, happens when -// 1. phpstan autoload test case is triggered first, -// 2. all php-parser classes are loaded, -if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) { - return; -} - if (! function_exists('isPHPStanTestPreloaded')) { function isPHPStanTestPreloaded(): bool { @@ -27,6 +20,13 @@ function isPHPStanTestPreloaded(): bool } } +// edge case during Rector tests case, happens when +// 1. phpstan autoload test case is triggered first, +// 2. all php-parser classes are loaded, +if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) { + return; +} + require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php'; require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php'; require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';