Skip to content

Commit f925a2e

Browse files
committed
Modified output
1 parent c6f5461 commit f925a2e

File tree

5 files changed

+60
-61
lines changed

5 files changed

+60
-61
lines changed

src/PipConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace ScriptFUSION\Pip;
56

6-
final class PipConfig
7-
{
7+
final class PipConfig {
88
public int $perfSlow = 200;
99
public int $perfVslow = 1_000;
1010
public bool $testDpArgs = true;

src/PipExtension.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
declare(strict_types = 1);
2+
3+
declare(strict_types=1);
34

45
namespace ScriptFUSION\Pip;
56

@@ -8,10 +9,8 @@
89
use PHPUnit\Runner\Extension\ParameterCollection;
910
use PHPUnit\TextUI\Configuration\Configuration;
1011

11-
final class PipExtension implements Extension
12-
{
13-
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void
14-
{
12+
final class PipExtension implements Extension {
13+
public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void {
1514
$config = new PipConfig();
1615
$parameters->has('perf.slow') && $config->perfSlow = +$parameters->get('perf.slow');
1716
$parameters->has('perf.vslow') && $config->perfVslow = +$parameters->get('perf.vslow');

src/Printer.php

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace ScriptFUSION\Pip;
@@ -21,8 +22,7 @@
2122
use PHPUnit\Event\Tracer\Tracer;
2223
use PHPUnit\Util\Color;
2324

24-
final class Printer implements Tracer
25-
{
25+
final class Printer implements Tracer {
2626
private readonly array $performanceThresholds;
2727

2828
private int $totalTests;
@@ -39,17 +39,15 @@ final class Printer implements Tracer
3939

4040
private bool $flawless = true;
4141

42-
public function __construct(private readonly PipConfig $config)
43-
{
42+
public function __construct(private readonly PipConfig $config) {
4443
$this->performanceThresholds = [
4544
'red' => $config->perfVslow,
4645
'yellow' => $config->perfSlow,
4746
'green' => 0,
4847
];
4948
}
5049

51-
public function trace(Event $event): void
52-
{
50+
public function trace(Event $event): void {
5351
if ($event instanceof ExecutionStarted) {
5452
$this->totalTests = $event->testSuite()->count();
5553
}
@@ -104,10 +102,15 @@ public function trace(Event $event): void
104102
}
105103

106104
if ($event instanceof Finished) {
107-
$id = $event->test()->id();
108-
if ($this->config->testNameStrip !== '') {
109-
$id = str_replace($this->config->testNameStrip, '', $id);
105+
$id = $event->test()->name(); // changed
106+
$id = str_replace('test', '', $id); //changed
107+
$id = str_replace('_', ' ', $id); //changed
108+
109+
// change block
110+
if ($this->trace && $this->status !== TestStatus::Failed && $this->status !== TestStatus::Errored) {
111+
$id .= Color::colorize('fg-yellow', '' . $this->trace->message);
110112
}
113+
// end change block
111114

112115
// Data provider case.
113116
if ($event->test()->isTestMethod() && $event->test()->testData()->hasDataFromDataProvider()) {
@@ -130,29 +133,29 @@ public function trace(Event $event): void
130133
}
131134

132135
printf(
133-
"%3d%% %s %s %s%s",
134-
floor(++$this->testCounter / $this->totalTests * 100),
136+
// "%3d%% %s %s %s%s",
137+
" %s %s %s %s%s",
138+
// " %s %s%s",
139+
'[' . str_pad(floor(++$this->testCounter / $this->totalTests * 100) . '', 3, ' ', STR_PAD_LEFT) . '%]',
135140
$this->status->getStatusColour() === ''
136141
? $this->status->getStatusCode()
137-
: Color::colorize("fg-{$this->status->getStatusColour()}", $this->status->getStatusCode()),
138-
Color::colorize("fg-{$this->status->getColour()}", $id),
142+
: Color::colorize("fg-{$this->status->getColour()}", $this->status->getStatusCode()), // changed
143+
Color::colorize('fg-dim', $id), // changed
139144
Color::colorize("fg-$colour", "($ms ms)"),
140145
PHP_EOL,
141146
);
142147

143-
if ($this->status === TestStatus::Failed) {
144-
echo PHP_EOL, Color::colorize('fg-red', $this->throwable->description()), PHP_EOL,
145-
Color::colorize('fg-red', $this->throwable->stackTrace()), PHP_EOL
146-
;
148+
// if ($this->status === TestStatus::Failed) {
149+
// echo PHP_EOL, Color::colorize('fg-red', $this->throwable->description()), PHP_EOL,
150+
// Color::colorize('fg-red', $this->throwable->stackTrace()), PHP_EOL;
147151

148-
$this->throwable = null;
149-
}
152+
// $this->throwable = null;
153+
// }
150154

151155
while ($this->status === TestStatus::Errored && $this->throwable) {
152156
echo PHP_EOL, Color::colorize('fg-white,bg-red', " {$this->throwable->className()} "), ' ',
153-
Color::colorize('fg-red', $this->throwable->message()), PHP_EOL, PHP_EOL,
154-
Color::colorize('fg-red', $this->throwable->stackTrace()), PHP_EOL
155-
;
157+
Color::colorize('fg-red', $this->throwable->message()), PHP_EOL, PHP_EOL,
158+
Color::colorize('fg-red', $this->throwable->stackTrace()), PHP_EOL;
156159

157160
if ($this->throwable->hasPrevious()) {
158161
echo Color::colorize('fg-red', 'Caused by');
@@ -163,18 +166,18 @@ public function trace(Event $event): void
163166
}
164167
}
165168

166-
if ($this->trace) {
167-
printf(
168-
Color::colorize("fg-{$this->status->getColour()}", '%s%s: %s in %s on line %s%1$s%1$s'),
169-
PHP_EOL,
170-
$this->status->name,
171-
$this->trace->message,
172-
$this->trace->file,
173-
$this->trace->line
174-
);
175-
176-
$this->trace = null;
177-
}
169+
// if ($this->trace) {
170+
// printf(
171+
// Color::colorize("fg-{$this->status->getColour()}", '%s%s: %s in %s on line %s%1$s%1$s'),
172+
// PHP_EOL,
173+
// $this->status->name,
174+
// $this->trace->message,
175+
// $this->trace->file,
176+
// $this->trace->line
177+
// );
178+
179+
// $this->trace = null;
180+
// }
178181

179182
$this->status = null;
180183
}

src/TestStatus.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace ScriptFUSION\Pip;
56

6-
enum TestStatus
7-
{
7+
enum TestStatus {
88
case Passed;
99
case Flawed;
1010
case Failed;
@@ -16,41 +16,38 @@ enum TestStatus
1616
case Warning;
1717
case Deprecated;
1818

19-
public function getStatusCode(): string
20-
{
19+
public function getStatusCode(): string {
2120
return match ($this) {
22-
self::Passed => '.',
21+
self::Passed => '',
2322
self::Flawed => '!',
24-
self::Failed => 'F',
25-
self::Errored => 'E',
23+
self::Failed => '', // changed
24+
self::Errored => '', // changed
2625
self::Skipped => 'S',
2726
self::Incomplete => 'I',
28-
self::Risky => 'R',
27+
self::Risky => '!', // changed
2928
self::Notice => 'N',
3029
self::Warning => 'W',
3130
self::Deprecated => 'D',
3231
};
3332
}
3433

35-
public function getStatusColour(): string
36-
{
34+
public function getStatusColour(): string {
3735
return match ($this) {
38-
self::Passed => '',
36+
self::Passed => 'green',
3937
self::Flawed => 'red',
4038
default => $this->getColour(),
4139
};
4240
}
4341

44-
public function getColour(): string
45-
{
42+
public function getColour(): string {
4643
return match ($this) {
47-
self::Passed,
44+
self::Passed => 'green,bold', // changed
4845
self::Flawed => 'green,bold',
4946
self::Failed,
5047
self::Errored => 'red,bold',
5148
self::Skipped => 'cyan,bold',
5249
self::Incomplete,
53-
self::Risky,
50+
self::Risky => 'yellow,bold', //changed
5451
self::Notice,
5552
self::Warning,
5653
self::Deprecated, => 'yellow,bold',

src/Trace.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace ScriptFUSION\Pip;
@@ -7,16 +8,15 @@
78
use PHPUnit\Event\Test\PhpNoticeTriggered;
89
use PHPUnit\Event\Test\PhpWarningTriggered;
910

10-
final class Trace
11-
{
11+
final class Trace {
1212
public function __construct(
1313
public readonly string $message,
1414
public readonly string $file,
1515
public readonly int $line,
16-
) {}
16+
) {
17+
}
1718

18-
public static function fromEvent(PhpWarningTriggered|PhpNoticeTriggered|PhpDeprecationTriggered $event): self
19-
{
19+
public static function fromEvent(PhpWarningTriggered|PhpNoticeTriggered|PhpDeprecationTriggered $event): self {
2020
return new self($event->message(), $event->file(), $event->line());
2121
}
2222
}

0 commit comments

Comments
 (0)