PestPHP `isBetween()` Expectation
This week in my free time, I've been working on a new Expectation for PestPHP which allows you to check whether a value, is between 2 other values.
The Expectation works with int
, float
and DateTime
types, and can be used like so:
// Int
expect(2)->toBeBetween(1, 3);
// Float
expect(1.5)->toBetween(1, 2);
// DateTime
expect(new DateTime('2023-09-22'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23'));
Now if you've used PestPHP, you may know about the not
function, well, you can also use isBetween()
with that too, to ensure a value is not between 2 values:
// Int
expect(4)->not->toBeBetween(1, 3);
// Float
expect(2.1)->not->toBetween(1.5, 1.75);
// DateTime
expect(new DateTime('2023-09-20'))->not->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23'));
I really enjoyed working on this Expectation, you can view the merged Pull Request on GitHub here. It will be released in v2.20.
UPDATE: You can now find this Expectation in the PestPHP Docs!