Skip to content

Commit d109a1a

Browse files
authored
refactor: fix dependency on test execution order (#10014)
* refactor: fix dependency on test execution order * reset in SignalTest
1 parent 68146b2 commit d109a1a

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

system/CLI/CLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ public static function reset(): void
11361136
static::$initialized = false;
11371137
static::$segments = [];
11381138
static::$options = [];
1139-
static::$lastWrite = 'write';
1139+
static::$lastWrite = null;
11401140
static::$height = null;
11411141
static::$width = null;
11421142
static::$isColored = static::hasColorSupport(STDOUT);

tests/system/CLI/CLITest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,23 +347,23 @@ public function testWriteForeground(): void
347347
{
348348
CLI::write('test', 'red');
349349

350-
$expected = "\033[0;31mtest\033[0m" . PHP_EOL;
350+
$expected = PHP_EOL . "\033[0;31mtest\033[0m" . PHP_EOL;
351351
$this->assertSame($expected, $this->getStreamFilterBuffer());
352352
}
353353

354354
public function testWriteForegroundWithColorBefore(): void
355355
{
356356
CLI::write(CLI::color('green', 'green') . ' red', 'red');
357357

358-
$expected = "\033[0;32mgreen\033[0m\033[0;31m red\033[0m" . PHP_EOL;
358+
$expected = PHP_EOL . "\033[0;32mgreen\033[0m\033[0;31m red\033[0m" . PHP_EOL;
359359
$this->assertSame($expected, $this->getStreamFilterBuffer());
360360
}
361361

362362
public function testWriteForegroundWithColorAfter(): void
363363
{
364364
CLI::write('red ' . CLI::color('green', 'green'), 'red');
365365

366-
$expected = "\033[0;31mred \033[0m\033[0;32mgreen\033[0m" . PHP_EOL;
366+
$expected = PHP_EOL . "\033[0;31mred \033[0m\033[0;32mgreen\033[0m" . PHP_EOL;
367367
$this->assertSame($expected, $this->getStreamFilterBuffer());
368368
}
369369

@@ -377,15 +377,15 @@ public function testWriteForegroundWithColorTwice(): void
377377
'red',
378378
);
379379

380-
$expected = "\033[0;32mgreen\033[0m\033[0;31m red \033[0m\033[0;32mgreen\033[0m" . PHP_EOL;
380+
$expected = PHP_EOL . "\033[0;32mgreen\033[0m\033[0;31m red \033[0m\033[0;32mgreen\033[0m" . PHP_EOL;
381381
$this->assertSame($expected, $this->getStreamFilterBuffer());
382382
}
383383

384384
public function testWriteBackground(): void
385385
{
386386
CLI::write('test', 'red', 'green');
387387

388-
$expected = "\033[0;31m\033[42mtest\033[0m" . PHP_EOL;
388+
$expected = PHP_EOL . "\033[0;31m\033[42mtest\033[0m" . PHP_EOL;
389389
$this->assertSame($expected, $this->getStreamFilterBuffer());
390390
}
391391

@@ -427,7 +427,7 @@ public function testShowProgress(): void
427427
CLI::write('third.');
428428
CLI::showProgress(1, 20);
429429

430-
$expected = 'first.' . PHP_EOL .
430+
$expected = PHP_EOL . 'first.' . PHP_EOL .
431431
"[\033[32m#.........\033[0m] 5% Complete" . PHP_EOL .
432432
"\033[1A[\033[32m#####.....\033[0m] 50% Complete" . PHP_EOL .
433433
"\033[1A[\033[32m##########\033[0m] 100% Complete" . PHP_EOL .
@@ -447,7 +447,7 @@ public function testShowProgressWithoutBar(): void
447447
CLI::showProgress(false, 20);
448448
CLI::showProgress(false, 20);
449449

450-
$expected = 'first.' . PHP_EOL . "\007\007\007";
450+
$expected = PHP_EOL . 'first.' . PHP_EOL . "\007\007\007";
451451
$this->assertSame($expected, $this->getStreamFilterBuffer());
452452
}
453453

@@ -620,13 +620,15 @@ public static function provideTable(): iterable
620620
[
621621
$oneRow,
622622
[],
623+
PHP_EOL .
623624
'+---+-----+' . PHP_EOL .
624625
'| 1 | bar |' . PHP_EOL .
625626
'+---+-----+' . PHP_EOL . PHP_EOL,
626627
],
627628
[
628629
$oneRow,
629630
$head,
631+
PHP_EOL .
630632
'+----+-------+' . PHP_EOL .
631633
'| ID | Title |' . PHP_EOL .
632634
'+----+-------+' . PHP_EOL .
@@ -636,6 +638,7 @@ public static function provideTable(): iterable
636638
[
637639
$manyRows,
638640
[],
641+
PHP_EOL .
639642
'+---+-----------------+' . PHP_EOL .
640643
'| 1 | bar |' . PHP_EOL .
641644
'| 2 | bar * 2 |' . PHP_EOL .
@@ -645,6 +648,7 @@ public static function provideTable(): iterable
645648
[
646649
$manyRows,
647650
$head,
651+
PHP_EOL .
648652
'+----+-----------------+' . PHP_EOL .
649653
'| ID | Title |' . PHP_EOL .
650654
'+----+-----------------+' . PHP_EOL .
@@ -665,6 +669,7 @@ public static function provideTable(): iterable
665669
'ID',
666670
'タイトル',
667671
],
672+
PHP_EOL .
668673
'+------+----------+' . PHP_EOL .
669674
'| ID | タイトル |' . PHP_EOL .
670675
'+------+----------+' . PHP_EOL .

tests/system/CLI/SignalTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ protected function setUp(): void
5353
$this->command = new SignalCommand($this->logger, service('commands'));
5454
}
5555

56+
protected function tearDown(): void
57+
{
58+
CLI::reset();
59+
60+
parent::tearDown();
61+
}
62+
5663
public function testSignalRegistration(): void
5764
{
5865
$this->command->testRegisterSignals([SIGTERM, SIGINT], [SIGTERM => 'customTermHandler']);

0 commit comments

Comments
 (0)