diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index b7c9ed64e2de..bafaeb167f12 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -1129,7 +1129,35 @@ protected static function fwrite($handle, string $string) /** * Testing purpose only * - * @testTag + * @internal + */ + public static function reset(): void + { + static::$initialized = false; + static::$segments = []; + static::$options = []; + static::$lastWrite = 'write'; + static::$height = null; + static::$width = null; + static::$isColored = static::hasColorSupport(STDOUT); + + static::resetInputOutput(); + } + + /** + * Testing purpose only + * + * @internal + */ + public static function resetLastWrite(): void + { + static::$lastWrite = null; + } + + /** + * Testing purpose only + * + * @internal */ public static function setInputOutput(InputOutput $io): void { @@ -1139,7 +1167,7 @@ public static function setInputOutput(InputOutput $io): void /** * Testing purpose only * - * @testTag + * @internal */ public static function resetInputOutput(): void { 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();