diff --git a/src/Event/Value/Test/TestDox.php b/src/Event/Value/Test/TestDox.php index 2703a368500..9e33718507c 100644 --- a/src/Event/Value/Test/TestDox.php +++ b/src/Event/Value/Test/TestDox.php @@ -14,17 +14,21 @@ * * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit */ -final readonly class TestDox +final class TestDox { - private string $prettifiedClassName; - private string $prettifiedMethodName; - private string $prettifiedAndColorizedMethodName; + private readonly string $prettifiedClassName; - public function __construct(string $prettifiedClassName, string $prettifiedMethodName, string $prettifiedAndColorizedMethodName) + /** @var callable */ + private $prettifiedMethodNameCallable; + + /** @var callable */ + private $prettifiedAndColorizedMethodNameCallable; + + public function __construct(string $prettifiedClassName, callable $prettifiedMethodNameCallable, callable $prettifiedAndColorizedMethodNameCallable) { - $this->prettifiedClassName = $prettifiedClassName; - $this->prettifiedMethodName = $prettifiedMethodName; - $this->prettifiedAndColorizedMethodName = $prettifiedAndColorizedMethodName; + $this->prettifiedClassName = $prettifiedClassName; + $this->prettifiedMethodNameCallable = $prettifiedMethodNameCallable; + $this->prettifiedAndColorizedMethodNameCallable = $prettifiedAndColorizedMethodNameCallable; } public function prettifiedClassName(): string @@ -35,9 +39,9 @@ public function prettifiedClassName(): string public function prettifiedMethodName(bool $colorize = false): string { if ($colorize) { - return $this->prettifiedAndColorizedMethodName; + return ($this->prettifiedAndColorizedMethodNameCallable)(); } - return $this->prettifiedMethodName; + return ($this->prettifiedMethodNameCallable)(); } } diff --git a/src/Event/Value/Test/TestDoxBuilder.php b/src/Event/Value/Test/TestDoxBuilder.php index ae8f62dad26..a979f28e3c5 100644 --- a/src/Event/Value/Test/TestDoxBuilder.php +++ b/src/Event/Value/Test/TestDoxBuilder.php @@ -23,8 +23,8 @@ public static function fromTestCase(TestCase $testCase): TestDox return new TestDox( $prettifier->prettifyTestClassName($testCase::class), - $prettifier->prettifyTestCase($testCase, false), - $prettifier->prettifyTestCase($testCase, true), + static fn () => $prettifier->prettifyTestCase($testCase, false), + static fn () => $prettifier->prettifyTestCase($testCase, true), ); } @@ -40,8 +40,8 @@ public static function fromClassNameAndMethodName(string $className, string $met return new TestDox( $prettifier->prettifyTestClassName($className), - $prettifiedMethodName, - $prettifiedMethodName, + static fn () => $prettifiedMethodName, + static fn () => $prettifiedMethodName, ); } }