From 4e9b91fc5f2f139041d139d7ef59380ada5a51ea Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 5 Dec 2023 22:57:02 +0100 Subject: [PATCH] Add missing tests as reported by coverage --- src/ZonedDateTime.php | 2 ++ tests/AbstractTestCase.php | 15 +++++++++++++++ tests/DayOfWeekTest.php | 1 + tests/MonthTest.php | 1 + tests/ZonedDateTimeTest.php | 5 +++++ 5 files changed, 24 insertions(+) diff --git a/src/ZonedDateTime.php b/src/ZonedDateTime.php index 0b1e41b..86b9d64 100644 --- a/src/ZonedDateTime.php +++ b/src/ZonedDateTime.php @@ -203,7 +203,9 @@ public static function fromNativeDateTime(DateTimeInterface $dateTime): ZonedDat $dateTimeZone = $dateTime->getTimezone(); if ($dateTimeZone === false) { + // @codeCoverageIgnoreStart throw new DateTimeException('This DateTime object has no timezone.'); + // @codeCoverageIgnoreEnd } $timeZone = TimeZone::fromNativeDateTimeZone($dateTimeZone); diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 3aef5e2..272fdf9 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -66,6 +66,10 @@ protected function assertLocalDateIs(int $year, int $month, int $day, LocalDate $date->getMonthValue(), $date->getDayOfMonth(), ]); + + // temporary assertions to test the deprecated getters as well + self::assertSame($month, $date->getMonth()); + self::assertSame($day, $date->getDay()); } /** @@ -106,6 +110,10 @@ protected function assertLocalDateTimeIs(int $y, int $m, int $d, int $h, int $i, $dateTime->getSecond(), $dateTime->getNano(), ]); + + // temporary assertions to test the deprecated getters as well + self::assertSame($m, $dateTime->getMonth()); + self::assertSame($d, $dateTime->getDay()); } /** @@ -135,6 +143,9 @@ protected function assertYearMonthIs(int $year, int $month, YearMonth $yearMonth $yearMonth->getYear(), $yearMonth->getMonthValue(), ]); + + // temporary assertion to test the deprecated getter as well + self::assertSame($month, $yearMonth->getMonth()); } /** @@ -161,6 +172,10 @@ protected function assertMonthDayIs(int $month, int $day, MonthDay $monthDay): v $monthDay->getMonthValue(), $monthDay->getDayOfMonth(), ]); + + // temporary assertions to test the deprecated getters as well + self::assertSame($month, $monthDay->getMonth()); + self::assertSame($day, $monthDay->getDay()); } /** diff --git a/tests/DayOfWeekTest.php b/tests/DayOfWeekTest.php index 45e9739..47c9437 100644 --- a/tests/DayOfWeekTest.php +++ b/tests/DayOfWeekTest.php @@ -29,6 +29,7 @@ class DayOfWeekTest extends AbstractTestCase public function testValues(int $expectedValue, DayOfWeek $dayOfWeek): void { self::assertSame($expectedValue, $dayOfWeek->value); + self::assertSame($expectedValue, $dayOfWeek->getValue()); } public function providerValues(): array diff --git a/tests/MonthTest.php b/tests/MonthTest.php index 84ac8b3..b01fa06 100644 --- a/tests/MonthTest.php +++ b/tests/MonthTest.php @@ -26,6 +26,7 @@ class MonthTest extends AbstractTestCase public function testValues(int $expectedValue, Month $month): void { self::assertSame($expectedValue, $month->value); + self::assertSame($expectedValue, $month->getValue()); } public function providerValues(): array diff --git a/tests/ZonedDateTimeTest.php b/tests/ZonedDateTimeTest.php index 9121eeb..8b54734 100644 --- a/tests/ZonedDateTimeTest.php +++ b/tests/ZonedDateTimeTest.php @@ -525,6 +525,11 @@ public function testGetYear(): void } public function testGetMonth(): void + { + self::assertSame(1, $this->getTestZonedDateTime()->getMonth()); + } + + public function testGetMonthValue(): void { self::assertSame(1, $this->getTestZonedDateTime()->getMonthValue()); }