Numeric Assertions
Numeric assertions validate numbers and perform comparison operations.
Available Assertions
Section titled “Available Assertions”lessThan()
Section titled “lessThan()”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');lessOrEqualThan()
Section titled “lessOrEqualThan()”Assert that a value is less than or equal to a limit.
Assertion::lessOrEqualThan($percentage, 100);Assertion::lessOrEqualThan($quantity, 10, 'Maximum quantity is 10');greaterThan()
Section titled “greaterThan()”Assert that a value is greater than a limit.
Assertion::greaterThan($age, 17);Assertion::greaterThan($price, 0, 'Price must be positive');greaterOrEqualThan()
Section titled “greaterOrEqualThan()”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');between()
Section titled “between()”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');betweenExclusive()
Section titled “betweenExclusive()”Assert that a value is between two limits (exclusive).
Assertion::betweenExclusive($temperature, 0, 100);range()
Section titled “range()”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');Chaining Numeric Assertions
Section titled “Chaining Numeric Assertions”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);Common Patterns
Section titled “Common Patterns”Age Validation
Section titled “Age Validation”Assert::that($age) ->integer() ->greaterOrEqualThan(0) ->lessThan(150);Price Validation
Section titled “Price Validation”Assert::that($price) ->float() ->greaterThan(0) ->max(1000000);Rating System (1-5)
Section titled “Rating System (1-5)”Assert::that($rating) ->integer() ->between(1, 5, 'Rating must be between 1 and 5');Percentage Validation
Section titled “Percentage Validation”Assert::that($percentage) ->numeric() ->greaterOrEqualThan(0) ->lessOrEqualThan(100);Quantity Validation
Section titled “Quantity Validation”Assert::that($quantity) ->integer() ->greaterThan(0, 'Quantity must be positive') ->max(999, 'Maximum quantity is 999');Working with Different Numeric Types
Section titled “Working with Different Numeric Types”Integer Validation
Section titled “Integer Validation”Assert::that($count) ->integer() ->greaterOrEqualThan(0);Float Validation
Section titled “Float Validation”Assert::that($latitude) ->float() ->between(-90, 90);Numeric Strings
Section titled “Numeric Strings”Assert::that($value) ->numeric() ->greaterThan(0);Next Steps
Section titled “Next Steps”- Type Assertions - Type checking for integers, floats
- Comparison Assertions - Equality operations
- Lazy Assertions - Validate multiple fields