Skip to content

Commit

Permalink
Add missing tests as reported by coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Dec 5, 2023
1 parent dc2049f commit 4e9b91f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ZonedDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/DayOfWeekTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/MonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/ZonedDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 4e9b91f

Please sign in to comment.