fusonic/assert

Extends beberlei/assert with a convenient chaining functionality

Installs: 1 406

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 6

Forks: 0

Open Issues: 0

pkg:composer/fusonic/assert

0.0.1 2025-03-12 06:57 UTC

This package is not auto-updated.

Last update: 2025-09-24 12:30:09 UTC


README

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.