-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DateTime::isNotBeforeOrEqualTo
- Loading branch information
Christian Kolb
committed
Sep 20, 2023
1 parent
f4346dd
commit 8032dd8
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimeParts\DateTime; | ||
|
||
use DigitalCraftsman\DateTimeParts\DateTime; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\DateTime */ | ||
final class IsNotBeforeOrEqualToTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider dataProvider | ||
* | ||
* @covers ::isNotBeforeOrEqualTo | ||
*/ | ||
public function is_not_before_or_equal_to_works( | ||
bool $expectedResult, | ||
DateTime $dateTime, | ||
DateTime $comparator, | ||
): void { | ||
// -- Act & Assert | ||
self::assertSame($expectedResult, $dateTime->isNotBeforeOrEqualTo($comparator)); | ||
} | ||
|
||
/** | ||
* @return array<string, array{ | ||
* 0: boolean, | ||
* 1: DateTime, | ||
* 2: DateTime, | ||
* }> | ||
*/ | ||
public function dataProvider(): array | ||
{ | ||
return [ | ||
'previous year' => [ | ||
false, | ||
DateTime::fromString('2021-10-08 15:00:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'is equal' => [ | ||
true, | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next year' => [ | ||
true, | ||
DateTime::fromString('2023-10-08 15:00:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next month' => [ | ||
true, | ||
DateTime::fromString('2022-11-08 15:00:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next day' => [ | ||
true, | ||
DateTime::fromString('2022-10-09 15:00:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next hour' => [ | ||
true, | ||
DateTime::fromString('2022-10-08 16:00:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next minute' => [ | ||
true, | ||
DateTime::fromString('2022-10-08 15:01:00'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next second' => [ | ||
true, | ||
DateTime::fromString('2022-10-08 15:00:01'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
'next millisecond' => [ | ||
true, | ||
DateTime::fromString('2022-10-08 15:00:00.000001'), | ||
DateTime::fromString('2022-10-08 15:00:00'), | ||
], | ||
]; | ||
} | ||
} |