From 5e84deefabf7d1a5f799be7e2e4cdf3dd2e07ecf Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Mon, 22 Jan 2024 07:34:00 +0100 Subject: [PATCH] Improve Info Test --- src/Enum/Info.php | 9 +++++++++ src/Enum/InfoTest.php | 20 ++++++++++++++++++++ src/Enum/README.md | 9 +++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Enum/Info.php b/src/Enum/Info.php index 22e9dd3..49a0e2c 100644 --- a/src/Enum/Info.php +++ b/src/Enum/Info.php @@ -72,4 +72,13 @@ public static function nameOf(string|int $value): ?string default => $res, }; } + + /** + * Convert the Enum into a Javascript structure. + */ + public static function toJavascript(): string + { + return JavascriptConverter::new() + ->convertToObject(static::class); /* @phpstan-ignore-line */ + } } diff --git a/src/Enum/InfoTest.php b/src/Enum/InfoTest.php index 488d064..de4b212 100644 --- a/src/Enum/InfoTest.php +++ b/src/Enum/InfoTest.php @@ -19,6 +19,16 @@ public function it_can_get_information_from_a_pure_enumeration(): void self::assertSame(['Top', 'Down', 'Left', 'Right'], Direction::names()); self::assertSame([], Direction::values()); self::assertNull(Direction::nameOf('Up')); + $expected = <<