-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Pip; | ||
|
||
use PHPUnit\Event\Code\Throwable; | ||
|
||
final class TestResult | ||
{ | ||
public function __construct( | ||
public readonly string $id, | ||
public readonly TestStatus $status, | ||
public readonly int $totalTests, | ||
public readonly int $testCounter, | ||
public readonly int $testDurationMs, | ||
public readonly string $testDurationColour, | ||
public readonly ?Throwable $throwable, | ||
public readonly ?Trace $trace, | ||
) { | ||
} | ||
|
||
public function calculateProgressPercentage(): int | ||
{ | ||
return floor($this->testCounter / $this->totalTests * 100)|0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Pip\Theme; | ||
|
||
use PHPUnit\Util\Color; | ||
use ScriptFUSION\Pip\TestResult; | ||
use ScriptFUSION\Pip\TestStatus; | ||
|
||
final class ClassicTheme implements Theme | ||
{ | ||
public function onTestFinished(TestResult $result): void | ||
{ | ||
printf( | ||
"%3d%% %s %s %s%s", | ||
$result->calculateProgressPercentage(), | ||
$result->status->getStatusColour() === '' | ||
? $result->status->getStatusCode() | ||
: Color::colorize("fg-{$result->status->getStatusColour()}", $result->status->getStatusCode()), | ||
Color::colorize("fg-{$result->status->getColour()}", $result->id), | ||
Color::colorize("fg-$result->testDurationColour", "($result->testDurationMs ms)"), | ||
PHP_EOL, | ||
); | ||
|
||
if ($result->status === TestStatus::Failed) { | ||
echo PHP_EOL, Color::colorize('fg-red', $result->throwable->description()), PHP_EOL, | ||
Color::colorize('fg-red', $result->throwable->stackTrace()), PHP_EOL | ||
; | ||
} | ||
|
||
while ($result->status === TestStatus::Errored && $throwable ??= $result->throwable) { | ||
echo PHP_EOL, Color::colorize('fg-white,bg-red', " {$throwable->className()} "), ' ', | ||
Color::colorize('fg-red', $throwable->message()), PHP_EOL, PHP_EOL, | ||
Color::colorize('fg-red', $throwable->stackTrace()), PHP_EOL | ||
; | ||
|
||
if (!$throwable->hasPrevious()) { | ||
break; | ||
} | ||
|
||
echo Color::colorize('fg-red', 'Caused by'); | ||
$throwable = $throwable->previous(); | ||
} | ||
|
||
if ($result->trace) { | ||
printf( | ||
Color::colorize("fg-{$result->status->getColour()}", '%s%s: %s in %s on line %s%1$s%1$s'), | ||
PHP_EOL, | ||
$result->status->name, | ||
$result->trace->message, | ||
$result->trace->file, | ||
$result->trace->line, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Pip\Theme; | ||
|
||
use ScriptFUSION\Pip\TestResult; | ||
|
||
interface Theme | ||
{ | ||
public function onTestFinished(TestResult $result): void; | ||
} |