Skip to content

Commit 72137d9

Browse files
Sprinkle some color
1 parent 8cbb9c2 commit 72137d9

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/TextUI/Command/Commands/CheckPhpConfigurationCommand.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use function sprintf;
1717
use function strlen;
1818
use PHPUnit\Runner\Version;
19+
use PHPUnit\Util\Color;
20+
use SebastianBergmann\Environment\Console;
1921

2022
/**
2123
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -64,6 +66,12 @@
6466
'requiredExtensions' => [],
6567
],
6668
];
69+
private bool $colorize;
70+
71+
public function __construct()
72+
{
73+
$this->colorize = (new Console)->hasColorSupport();
74+
}
6775

6876
public function execute(): Result
6977
{
@@ -78,9 +86,9 @@ public function execute(): Result
7886
}
7987

8088
if (ini_get($name) === $setting['expectedValue']) {
81-
$check = 'ok';
89+
$check = $this->ok();
8290
} else {
83-
$check = 'not ok';
91+
$check = $this->notOk();
8492
$shellExitCode = 1;
8593
}
8694

@@ -115,4 +123,28 @@ public function execute(): Result
115123

116124
return Result::from($buffer, $shellExitCode);
117125
}
126+
127+
/**
128+
* @return non-empty-string
129+
*/
130+
private function ok(): string
131+
{
132+
if (!$this->colorize) {
133+
return 'ok';
134+
}
135+
136+
return Color::colorizeTextBox('fg-green, bold', 'ok');
137+
}
138+
139+
/**
140+
* @return non-empty-string
141+
*/
142+
private function notOk(): string
143+
{
144+
if (!$this->colorize) {
145+
return 'not ok';
146+
}
147+
148+
return Color::colorizeTextBox('fg-red, bold', 'not ok');
149+
}
118150
}

0 commit comments

Comments
 (0)