Skip to content

Commit d0e704d

Browse files
Refactor
1 parent 1907013 commit d0e704d

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Event/Value/Test/TestDoxBuilder.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
*
1818
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1919
*/
20-
final readonly class TestDoxBuilder
20+
final class TestDoxBuilder
2121
{
22+
private static ?NamePrettifier $namePrettifier = null;
23+
2224
public static function fromTestCase(TestCase $testCase): TestDox
2325
{
24-
$prettifier = new NamePrettifier;
26+
$prettifier = self::namePrettifier();
2527

2628
return new TestDox(
2729
$prettifier->prettifyTestClassName($testCase::class),
@@ -36,7 +38,7 @@ public static function fromTestCase(TestCase $testCase): TestDox
3638
*/
3739
public static function fromClassNameAndMethodName(string $className, string $methodName): TestDox
3840
{
39-
$prettifier = new NamePrettifier;
41+
$prettifier = self::namePrettifier();
4042

4143
$prettifiedMethodName = $prettifier->prettifyTestMethodName($methodName);
4244

@@ -46,4 +48,13 @@ public static function fromClassNameAndMethodName(string $className, string $met
4648
$prettifiedMethodName,
4749
);
4850
}
51+
52+
private static function namePrettifier(): NamePrettifier
53+
{
54+
if (self::$namePrettifier === null) {
55+
self::$namePrettifier = new NamePrettifier;
56+
}
57+
58+
return self::$namePrettifier;
59+
}
4960
}

src/Logging/TestDox/NamePrettifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ final class NamePrettifier
5757
/**
5858
* @var array<string, int>
5959
*/
60-
private static array $strings = [];
60+
private array $strings = [];
6161

6262
/**
6363
* @param class-string $className
@@ -118,10 +118,10 @@ public function prettifyTestMethodName(string $name): string
118118

119119
$string = rtrim($name, '0123456789');
120120

121-
if (array_key_exists($string, self::$strings)) {
121+
if (array_key_exists($string, $this->strings)) {
122122
$name = $string;
123123
} elseif ($string === $name) {
124-
self::$strings[$string] = 1;
124+
$this->strings[$string] = 1;
125125
}
126126

127127
if (str_starts_with($name, 'test_')) {

0 commit comments

Comments
 (0)