diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 0513face..d087162d 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -124,7 +124,7 @@ final class Expectation * * @return self */ - public function toBeGreaterThan(int|float $expected, string $message = ''): self + public function toBeGreaterThan(int|float|\DateTime|\DateTimeImmutable $expected, string $message = ''): self { Assert::assertGreaterThan($expected, $this->value, $message); @@ -136,7 +136,7 @@ final class Expectation * * @return self */ - public function toBeGreaterThanOrEqual(int|float $expected, string $message = ''): self + public function toBeGreaterThanOrEqual(int|float|\DateTime|\DateTimeImmutable $expected, string $message = ''): self { Assert::assertGreaterThanOrEqual($expected, $this->value, $message); @@ -148,7 +148,7 @@ final class Expectation * * @return self */ - public function toBeLessThan(int|float $expected, string $message = ''): self + public function toBeLessThan(int|float|\DateTime|\DateTimeImmutable $expected, string $message = ''): self { Assert::assertLessThan($expected, $this->value, $message); @@ -160,7 +160,7 @@ final class Expectation * * @return self */ - public function toBeLessThanOrEqual(int|float $expected, string $message = ''): self + public function toBeLessThanOrEqual(int|float|\DateTime|\DateTimeImmutable $expected, string $message = ''): self { Assert::assertLessThanOrEqual($expected, $this->value, $message); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 217f831f..2db57d3f 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -334,12 +334,14 @@ PASS Tests\Features\Expect\toBeGreatherThan ✓ passes + ✓ passes with DateTime and DateTimeImmutable ✓ failures ✓ failures with custom message ✓ not failures PASS Tests\Features\Expect\toBeGreatherThanOrEqual ✓ passes + ✓ passes with DateTime and DateTimeImmutable ✓ failures ✓ failures with custom message ✓ not failures @@ -382,12 +384,14 @@ PASS Tests\Features\Expect\toBeLessThan ✓ passes + ✓ passes with DateTime and DateTimeImmutable ✓ failures ✓ failures with custom message ✓ not failures PASS Tests\Features\Expect\toBeLessThanOrEqual ✓ passes + ✓ passes with DateTime and DateTimeImmutable ✓ failures ✓ failures with custom message ✓ not failures @@ -990,4 +994,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 695 passed (1680 assertions) \ No newline at end of file + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 695 passed (1680 assertions) diff --git a/tests/Features/Expect/toBeGreatherThan.php b/tests/Features/Expect/toBeGreatherThan.php index 798c23bb..a3ceafef 100644 --- a/tests/Features/Expect/toBeGreatherThan.php +++ b/tests/Features/Expect/toBeGreatherThan.php @@ -7,6 +7,15 @@ test('passes', function () { expect(4)->toBeGreaterThan(3.9); }); +test('passes with DateTime and DateTimeImmutable', function () { + $now = new DateTime(); + $past = (new DateTimeImmutable())->modify('-1 day'); + + expect($now)->toBeGreaterThan($past); + + expect($past)->not->toBeGreaterThan($now); +}); + test('failures', function () { expect(4)->toBeGreaterThan(4); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeGreatherThanOrEqual.php b/tests/Features/Expect/toBeGreatherThanOrEqual.php index cfa1da07..4a0f62ad 100644 --- a/tests/Features/Expect/toBeGreatherThanOrEqual.php +++ b/tests/Features/Expect/toBeGreatherThanOrEqual.php @@ -7,6 +7,17 @@ test('passes', function () { expect(4)->toBeGreaterThanOrEqual(4); }); +test('passes with DateTime and DateTimeImmutable', function () { + $now = new DateTime(); + $past = (new DateTimeImmutable())->modify('-1 day'); + + expect($now)->toBeGreaterThanOrEqual($now); + + expect($now)->toBeGreaterThanOrEqual($past); + + expect($past)->not->toBeGreaterThanOrEqual($now); +}); + test('failures', function () { expect(4)->toBeGreaterThanOrEqual(4.1); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeLessThan.php b/tests/Features/Expect/toBeLessThan.php index 9002c424..802c1c08 100644 --- a/tests/Features/Expect/toBeLessThan.php +++ b/tests/Features/Expect/toBeLessThan.php @@ -7,6 +7,15 @@ test('passes', function () { expect(4)->toBeLessThan(5); }); +test('passes with DateTime and DateTimeImmutable', function () { + $now = new DateTime(); + $past = (new DateTimeImmutable())->modify('-1 day'); + + expect($past)->toBeLessThan($now); + + expect($now)->not->toBeLessThan($now); +}); + test('failures', function () { expect(4)->toBeLessThan(4); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeLessThanOrEqual.php b/tests/Features/Expect/toBeLessThanOrEqual.php index 4413e05f..e5643759 100644 --- a/tests/Features/Expect/toBeLessThanOrEqual.php +++ b/tests/Features/Expect/toBeLessThanOrEqual.php @@ -7,6 +7,17 @@ test('passes', function () { expect(4)->toBeLessThanOrEqual(4); }); +test('passes with DateTime and DateTimeImmutable', function () { + $now = new DateTime(); + $past = (new DateTimeImmutable())->modify('-1 day'); + + expect($now)->toBeLessThanOrEqual($now); + + expect($past)->toBeLessThanOrEqual($now); + + expect($now)->not->toBeLessThanOrEqual($past); +}); + test('failures', function () { expect(4)->toBeLessThanOrEqual(3.9); })->throws(ExpectationFailedException::class);