From 7310295297733715005a276e05e51bce40ab300f Mon Sep 17 00:00:00 2001 From: Dorian Villet Date: Sat, 30 Sep 2023 11:16:41 +0200 Subject: [PATCH] Add Month::getName() method (same as __toString()). --- src/Month.php | 8 ++++++++ tests/MonthTest.php | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Month.php b/src/Month.php index ee470b5..625e56e 100644 --- a/src/Month.php +++ b/src/Month.php @@ -233,6 +233,14 @@ public function jsonSerialize(): string return (string) $this; } + /** + * {@see __toString()}. + */ + public function getName(): string + { + return (string) $this; + } + /** * Returns the capitalized English name of this Month. */ diff --git a/tests/MonthTest.php b/tests/MonthTest.php index af7c76a..ed3db7c 100644 --- a/tests/MonthTest.php +++ b/tests/MonthTest.php @@ -302,6 +302,17 @@ public function testJsonSerialize(int $month, string $expectedName): void self::assertSame(json_encode($expectedName), json_encode(Month::of($month))); } + /** + * @dataProvider providerToString + * + * @param int $month The month number. + * @param string $expectedName The expected month name. + */ + public function testGetName(int $month, string $expectedName): void + { + self::assertSame($expectedName, Month::of($month)->getName()); + } + /** * @dataProvider providerToString *