fusonic / assert
Extends beberlei/assert with a convenient chaining functionality
0.0.1
2025-03-12 06:57 UTC
Requires
- php: >=8.2
- beberlei/assert: ^3.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- infection/infection: ^0.29
- phpstan/phpstan: ^1.12
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-phpunit: ^1.4
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^11.3
- tomasvotruba/type-coverage: ^0.3
This package is not auto-updated.
Last update: 2025-03-15 07:14:33 UTC
README
About
This assertion library extends beberlei/assert with convenient chaining functionality to improve error message details.
- Wraps all chained and non-chained assertion errors in the same exception object.
- Lazy validation with a defined root path (e.g. an object class name)
- Single assertions with a separate root path as a first argument
Install
Use composer to install the library from packagist.
composer require fusonic/assert
Usage
Regular assertion with root path:
Assert::that('User', 'username', $username)->notEmpty()->length(10);
Chained lazy assertion with root path example:
Assert::lazy('User') ->that($username, 'username') ->notEmpty() ->that($password, 'password') ->minLength(8) ->maxLength(30) ->verifyNow();
Example output:
The following 2 assertions failed:
1) User.username: Value "" is empty, but non empty value was expected.
2) User.password: Value "1123" is too short, it should have at least 8 characters, but only has 4 characters.