Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -1139,7 +1167,7 @@ public static function setInputOutput(InputOutput $io): void
/**
* Testing purpose only
*
* @testTag
* @internal
*/
public static function resetInputOutput(): void
{
Expand Down
15 changes: 11 additions & 4 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -330,6 +335,8 @@ public function testPrintBackground(): void

public function testWrite(): void
{
CLI::resetLastWrite();

CLI::write('test');

$expected = PHP_EOL . 'test' . PHP_EOL;
Expand Down
8 changes: 8 additions & 0 deletions tests/system/CLI/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected function setUp(): void
parent::setUp();

Services::injectMock('superglobals', new Superglobals());
CLI::init();

$env = new DotEnv(ROOTPATH);
$env->load();
Expand All @@ -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();
Expand Down
Loading