From fe0a2558bbe03f231f89ea1ba46e1f2e09278952 Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 24 Feb 2026 14:01:36 +0100 Subject: [PATCH 1/3] refactor: make random-order CLI tests deterministic --- system/CLI/CLI.php | 28 ++++++++++++++++++++++++++++ tests/system/CLI/CLITest.php | 15 +++++++++++---- tests/system/CLI/ConsoleTest.php | 8 ++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index b7c9ed64e2de..8a30c4cf0c73 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -1126,6 +1126,34 @@ protected static function fwrite($handle, string $string) static::$io->fwrite($handle, $string); } + /** + * Testing purpose only + * + * @testTag + */ + public static function reset(): void + { + static::$initialized = false; + static::$segments = []; + static::$options = []; + static::$lastWrite = 'write'; + static::$height = null; + static::$width = null; + static::$isColored = false; + + static::resetInputOutput(); + } + + /** + * Testing purpose only + * + * @testTag + */ + public static function resetLastWrite(): void + { + static::$lastWrite = null; + } + /** * Testing purpose only * diff --git a/tests/system/CLI/CLITest.php b/tests/system/CLI/CLITest.php index 146d1066766e..6c6ce4569c4c 100644 --- a/tests/system/CLI/CLITest.php +++ b/tests/system/CLI/CLITest.php @@ -36,6 +36,15 @@ protected function setUp(): void parent::setUp(); Services::injectMock('superglobals', new Superglobals()); + + CLI::init(); + } + + protected function tearDown(): void + { + CLI::reset(); + + parent::tearDown(); } public function testNew(): void @@ -286,10 +295,6 @@ public function testStreamSupports(): void public function testColor(): void { - // After the tests on NO_COLOR and TERM_PROGRAM above, - // the $isColored variable is rigged. So we reset this. - CLI::init(); - $this->assertSame( "\033[1;37m\033[42m\033[4mtest\033[0m", CLI::color('test', 'white', 'green', 'underline'), @@ -330,6 +335,8 @@ public function testPrintBackground(): void public function testWrite(): void { + CLI::resetLastWrite(); + CLI::write('test'); $expected = PHP_EOL . 'test' . PHP_EOL; diff --git a/tests/system/CLI/ConsoleTest.php b/tests/system/CLI/ConsoleTest.php index 8110698c4212..ff4ac02ab29b 100644 --- a/tests/system/CLI/ConsoleTest.php +++ b/tests/system/CLI/ConsoleTest.php @@ -37,6 +37,7 @@ protected function setUp(): void parent::setUp(); Services::injectMock('superglobals', new Superglobals()); + CLI::init(); $env = new DotEnv(ROOTPATH); $env->load(); @@ -50,6 +51,13 @@ protected function setUp(): void $this->app->initialize(); } + protected function tearDown(): void + { + CLI::reset(); + + parent::tearDown(); + } + public function testHeader(): void { $console = new Console(); From 618618b2c693ed071e3cae5d8940ce9a86aca9ba Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 24 Feb 2026 14:44:42 +0100 Subject: [PATCH 2/3] fix CLI::reset() --- system/CLI/CLI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 8a30c4cf0c73..0721fe0a9926 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -1139,7 +1139,7 @@ public static function reset(): void static::$lastWrite = 'write'; static::$height = null; static::$width = null; - static::$isColored = false; + static::$isColored = static::hasColorSupport(STDOUT); static::resetInputOutput(); } From 153753490d6657e5f2c661a664d2818487f14953 Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 24 Feb 2026 16:25:28 +0100 Subject: [PATCH 3/3] apply code suggestion --- system/CLI/CLI.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 0721fe0a9926..bafaeb167f12 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -1129,7 +1129,7 @@ protected static function fwrite($handle, string $string) /** * Testing purpose only * - * @testTag + * @internal */ public static function reset(): void { @@ -1147,7 +1147,7 @@ public static function reset(): void /** * Testing purpose only * - * @testTag + * @internal */ public static function resetLastWrite(): void { @@ -1157,7 +1157,7 @@ public static function resetLastWrite(): void /** * Testing purpose only * - * @testTag + * @internal */ public static function setInputOutput(InputOutput $io): void { @@ -1167,7 +1167,7 @@ public static function setInputOutput(InputOutput $io): void /** * Testing purpose only * - * @testTag + * @internal */ public static function resetInputOutput(): void {