Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve types in Greater/Lesser Expectations #716

Merged
merged 3 commits into from Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 653 passed (1604 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
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Expand Up @@ -15,6 +15,6 @@
};

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');