Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 1.72 KB

README.md

File metadata and controls

55 lines (40 loc) · 1.72 KB

assert

License Latest Version Total Downloads php 8.2+

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.