Skip to content

Commit

Permalink
Merge pull request #716 from dansysanalyst/improve_types
Browse files Browse the repository at this point in the history
Improve types in Greater/Lesser Expectations
  • Loading branch information
nunomaduro committed Mar 21, 2023
2 parents c34f649 + 88f29e4 commit 9a41f2f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Mixins/Expectation.php
Expand Up @@ -124,7 +124,7 @@ public function toBeFalsy(string $message = ''): self
*
* @return self<TValue>
*/
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);

Expand All @@ -136,7 +136,7 @@ public function toBeGreaterThan(int|float $expected, string $message = ''): self
*
* @return self<TValue>
*/
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);

Expand All @@ -148,7 +148,7 @@ public function toBeGreaterThanOrEqual(int|float $expected, string $message = ''
*
* @return self<TValue>
*/
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);

Expand All @@ -160,7 +160,7 @@ public function toBeLessThan(int|float $expected, string $message = ''): self
*
* @return self<TValue>
*/
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);

Expand Down
6 changes: 5 additions & 1 deletion tests/.snapshots/success.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 695 passed (1680 assertions)
9 changes: 9 additions & 0 deletions tests/Features/Expect/toBeGreatherThan.php
Expand Up @@ -7,6 +7,15 @@
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);
Expand Down
11 changes: 11 additions & 0 deletions tests/Features/Expect/toBeGreatherThanOrEqual.php
Expand Up @@ -7,6 +7,17 @@
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);
Expand Down
9 changes: 9 additions & 0 deletions tests/Features/Expect/toBeLessThan.php
Expand Up @@ -7,6 +7,15 @@
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);
Expand Down
11 changes: 11 additions & 0 deletions tests/Features/Expect/toBeLessThanOrEqual.php
Expand Up @@ -7,6 +7,17 @@
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);
Expand Down

0 comments on commit 9a41f2f

Please sign in to comment.