From a8bd353ba6da06f44dea0c955ab61b8f9a461bb3 Mon Sep 17 00:00:00 2001 From: Dan Ang Date: Tue, 21 Mar 2023 14:37:31 +0100 Subject: [PATCH] Including tests for Date and DateTimeImmutable --- tests/.snapshots/success.txt | 6 +++++- tests/Features/Expect/toBeGreatherThan.php | 9 +++++++++ tests/Features/Expect/toBeGreatherThanOrEqual.php | 11 +++++++++++ tests/Features/Expect/toBeLessThan.php | 9 +++++++++ tests/Features/Expect/toBeLessThanOrEqual.php | 11 +++++++++++ tests/Visual/Parallel.php | 2 +- 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 083ec696..ad025028 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 @@ -944,4 +948,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 649 passed (1588 assertions) \ No newline at end of file + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 653 passed (1604 assertions) \ No newline at end of file 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); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 16ca7396..b3817ef7 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -15,6 +15,6 @@ $run = function () { }; test('parallel', function () use ($run) { - expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 9 skipped, 640 passed (1576 assertions)') + expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 9 skipped, 644 passed (1592 assertions)') ->toContain('Parallel: 3 processes'); })->skip(PHP_OS_FAMILY === 'Windows');