mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Merge pull request #1055 from mapon-com/feature/string-comparison-expectations
[2.x] Allow string type in greaterThan/lessThan expectations
This commit is contained in:
@ -131,7 +131,7 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function toBeGreaterThan(int|float|DateTimeInterface $expected, string $message = ''): self
|
public function toBeGreaterThan(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||||
{
|
{
|
||||||
Assert::assertGreaterThan($expected, $this->value, $message);
|
Assert::assertGreaterThan($expected, $this->value, $message);
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function toBeGreaterThanOrEqual(int|float|DateTimeInterface $expected, string $message = ''): self
|
public function toBeGreaterThanOrEqual(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||||
{
|
{
|
||||||
Assert::assertGreaterThanOrEqual($expected, $this->value, $message);
|
Assert::assertGreaterThanOrEqual($expected, $this->value, $message);
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function toBeLessThan(int|float|DateTimeInterface $expected, string $message = ''): self
|
public function toBeLessThan(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||||
{
|
{
|
||||||
Assert::assertLessThan($expected, $this->value, $message);
|
Assert::assertLessThan($expected, $this->value, $message);
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ final class Expectation
|
|||||||
*
|
*
|
||||||
* @return self<TValue>
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function toBeLessThanOrEqual(int|float|DateTimeInterface $expected, string $message = ''): self
|
public function toBeLessThanOrEqual(int|float|string|DateTimeInterface $expected, string $message = ''): self
|
||||||
{
|
{
|
||||||
Assert::assertLessThanOrEqual($expected, $this->value, $message);
|
Assert::assertLessThanOrEqual($expected, $this->value, $message);
|
||||||
|
|
||||||
|
|||||||
@ -430,6 +430,7 @@
|
|||||||
PASS Tests\Features\Expect\toBeGreaterThan
|
PASS Tests\Features\Expect\toBeGreaterThan
|
||||||
✓ passes
|
✓ passes
|
||||||
✓ passes with DateTime and DateTimeImmutable
|
✓ passes with DateTime and DateTimeImmutable
|
||||||
|
✓ passes with strings
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
@ -437,6 +438,7 @@
|
|||||||
PASS Tests\Features\Expect\toBeGreaterThanOrEqual
|
PASS Tests\Features\Expect\toBeGreaterThanOrEqual
|
||||||
✓ passes
|
✓ passes
|
||||||
✓ passes with DateTime and DateTimeImmutable
|
✓ passes with DateTime and DateTimeImmutable
|
||||||
|
✓ passes with strings
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
@ -494,6 +496,7 @@
|
|||||||
PASS Tests\Features\Expect\toBeLessThan
|
PASS Tests\Features\Expect\toBeLessThan
|
||||||
✓ passes
|
✓ passes
|
||||||
✓ passes with DateTime and DateTimeImmutable
|
✓ passes with DateTime and DateTimeImmutable
|
||||||
|
✓ passes with strings
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
@ -501,6 +504,7 @@
|
|||||||
PASS Tests\Features\Expect\toBeLessThanOrEqual
|
PASS Tests\Features\Expect\toBeLessThanOrEqual
|
||||||
✓ passes
|
✓ passes
|
||||||
✓ passes with DateTime and DateTimeImmutable
|
✓ passes with DateTime and DateTimeImmutable
|
||||||
|
✓ passes with strings
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|||||||
@ -16,6 +16,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
|||||||
expect($past)->not->toBeGreaterThan($now);
|
expect($past)->not->toBeGreaterThan($now);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('passes with strings', function () {
|
||||||
|
expect('b')->toBeGreaterThan('a');
|
||||||
|
expect('a')->not->toBeGreaterThan('a');
|
||||||
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect(4)->toBeGreaterThan(4);
|
expect(4)->toBeGreaterThan(4);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -18,6 +18,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
|||||||
expect($past)->not->toBeGreaterThanOrEqual($now);
|
expect($past)->not->toBeGreaterThanOrEqual($now);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('passes with strings', function () {
|
||||||
|
expect('b')->toBeGreaterThanOrEqual('a');
|
||||||
|
expect('a')->toBeGreaterThanOrEqual('a');
|
||||||
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect(4)->toBeGreaterThanOrEqual(4.1);
|
expect(4)->toBeGreaterThanOrEqual(4.1);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -16,6 +16,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
|||||||
expect($now)->not->toBeLessThan($now);
|
expect($now)->not->toBeLessThan($now);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('passes with strings', function () {
|
||||||
|
expect('a')->toBeLessThan('b');
|
||||||
|
expect('a')->not->toBeLessThan('a');
|
||||||
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect(4)->toBeLessThan(4);
|
expect(4)->toBeLessThan(4);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -18,6 +18,11 @@ test('passes with DateTime and DateTimeImmutable', function () {
|
|||||||
expect($now)->not->toBeLessThanOrEqual($past);
|
expect($now)->not->toBeLessThanOrEqual($past);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('passes with strings', function () {
|
||||||
|
expect('a')->toBeLessThanOrEqual('b');
|
||||||
|
expect('a')->toBeLessThanOrEqual('a');
|
||||||
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect(4)->toBeLessThanOrEqual(3.9);
|
expect(4)->toBeLessThanOrEqual(3.9);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user