Skip to content

Commit ee1c46b

Browse files
committed
Fixed bug in calculation of Assert::isInMonth
1 parent d9d251e commit ee1c46b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Assertions/DateTimeAssertions.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,14 @@ public static function isInLastMonth($value, $message = '')
606606
public static function isInMonth($value, $monthNumber, $message = '')
607607
{
608608
$value = self::convertToDateTime($value);
609+
$currentYear = date('Y');
609610

610-
if ($value->format('n') != $monthNumber) {
611+
612+
if ($currentYear != $value->format('Y') ||
613+
$monthNumber != $value->format('n')
614+
) {
611615
throw new AssertionException(
612-
($message) ? $message : sprintf(self::ASSERT_IS_IN_MONTH, (new DateTime($monthNumber))->format('F'))
616+
($message) ? $message : sprintf(self::ASSERT_IS_IN_MONTH, (new DateTime('1970-'.$monthNumber.'-01'))->format('F'))
613617
);
614618
}
615619
}

tests/AssertDateTimeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function testItIsInLastMonthThrowsException()
394394

395395
public function testItIsInMonth()
396396
{
397-
$next = new DateTime('07-02-2015');
397+
$next = new DateTime('01-02-'.date('Y'));
398398
Assert::isInMonth($next, 2);
399399
}
400400

0 commit comments

Comments
 (0)