Skip to content

Numeric Assertions

Numeric assertions validate numbers and perform comparison operations.

Assert that a value is less than a limit.

use Cline\Assert\Assertions\Assertion;
Assertion::lessThan($age, 18);
Assertion::lessThan($score, 100, 'Score must be less than 100');

Assert that a value is less than or equal to a limit.

Assertion::lessOrEqualThan($percentage, 100);
Assertion::lessOrEqualThan($quantity, 10, 'Maximum quantity is 10');

Assert that a value is greater than a limit.

Assertion::greaterThan($age, 17);
Assertion::greaterThan($price, 0, 'Price must be positive');

Assert that a value is greater than or equal to a limit.

Assertion::greaterOrEqualThan($age, 18);
Assertion::greaterOrEqualThan($rating, 1, 'Rating must be at least 1');

Assert that a value is between two limits (inclusive).

Assertion::between($age, 18, 65);
Assertion::between($score, 0, 100, 'Score must be between 0 and 100');

Assert that a value is between two limits (exclusive).

Assertion::betweenExclusive($temperature, 0, 100);

Alias for between().

Assertion::range($month, 1, 12);
Assertion::range($hour, 0, 23);

Assert minimum value.

Assertion::min($quantity, 1);
Assertion::min($price, 0.01, 'Price must be at least $0.01');

Assert maximum value.

Assertion::max($discount, 100);
Assertion::max($items, 50, 'Maximum 50 items allowed');
use Cline\Assert\Assert;
Assert::that($age)
->integer()
->greaterOrEqualThan(18)
->lessThan(100);
Assert::that($price)
->float()
->greaterThan(0)
->max(9999.99);
Assert::that($percentage)
->numeric()
->between(0, 100);
Assert::that($age)
->integer()
->greaterOrEqualThan(0)
->lessThan(150);
Assert::that($price)
->float()
->greaterThan(0)
->max(1000000);
Assert::that($rating)
->integer()
->between(1, 5, 'Rating must be between 1 and 5');
Assert::that($percentage)
->numeric()
->greaterOrEqualThan(0)
->lessOrEqualThan(100);
Assert::that($quantity)
->integer()
->greaterThan(0, 'Quantity must be positive')
->max(999, 'Maximum quantity is 999');
Assert::that($count)
->integer()
->greaterOrEqualThan(0);
Assert::that($latitude)
->float()
->between(-90, 90);
Assert::that($value)
->numeric()
->greaterThan(0);