Skip to content

Commit

Permalink
Speed optimize test case pretty printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Mar 12, 2024
1 parent e04999a commit 76c826f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/Event/Value/Test/TestDoxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
*/
final readonly class TestDoxBuilder
{
public static function fromTestCase(TestCase $testCase): TestDox
public static function fromTestCase(TestCase $testCase, bool $colorize): TestDox
{
$prettifier = new NamePrettifier;

$prettyTestCase = $prettifier->prettifyTestCase($testCase, false);

if ($colorize) {
$prettyTestCaseColorized = $prettifier->prettifyTestCase($testCase, true);
} else {
$prettyTestCaseColorized = $prettyTestCase;
}

return new TestDox(
$prettifier->prettifyTestClassName($testCase::class),
$prettifier->prettifyTestCase($testCase, false),
$prettifier->prettifyTestCase($testCase, true),
$prettyTestCase,
$prettyTestCaseColorized,
);
}

Expand All @@ -34,8 +42,7 @@ public static function fromTestCase(TestCase $testCase): TestDox
*/
public static function fromClassNameAndMethodName(string $className, string $methodName): TestDox
{
$prettifier = new NamePrettifier;

$prettifier = new NamePrettifier;
$prettifiedMethodName = $prettifier->prettifyTestMethodName($methodName);

return new TestDox(
Expand Down
4 changes: 3 additions & 1 deletion src/Event/Value/Test/TestMethodBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPUnit\Event\TestData\TestDataCollection;
use PHPUnit\Framework\TestCase;
use PHPUnit\Metadata\Parser\Registry as MetadataRegistry;
use PHPUnit\TextUI\Configuration\Registry;
use PHPUnit\Util\Reflection;
use SebastianBergmann\Exporter\Exporter;

Expand All @@ -32,13 +33,14 @@ public static function fromTestCase(TestCase $testCase): TestMethod
assert(!empty($methodName));

$location = Reflection::sourceLocationFor($testCase::class, $methodName);
$colors = Registry::get()->colors();

return new TestMethod(
$testCase::class,
$methodName,
$location['file'],
$location['line'],
TestDoxBuilder::fromTestCase($testCase),
TestDoxBuilder::fromTestCase($testCase, $colors),
MetadataRegistry::parser()->forClassAndMethod($testCase::class, $methodName),
self::dataFor($testCase),
);
Expand Down

0 comments on commit 76c826f

Please sign in to comment.