Merge pull request #716 from dansysanalyst/improve_types

Improve types in Greater/Lesser Expectations
This commit is contained in:
Nuno Maduro
2023-03-21 20:30:34 +00:00
committed by GitHub
6 changed files with 49 additions and 5 deletions

View File

@ -124,7 +124,7 @@ final class Expectation
*
* @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);
@ -136,7 +136,7 @@ final class Expectation
*
* @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);
@ -148,7 +148,7 @@ final class Expectation
*
* @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);
@ -160,7 +160,7 @@ final class Expectation
*
* @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);

View File

@ -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)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 695 passed (1680 assertions)

View File

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

View File

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

View File

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

View File

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