Leo

Next level assertion and matcher library for PHP 5.4+

Expect

<?php
expect([1,2,3])->to->have->length(3);
expect($name)->to->be->a('string')
expect($object)->to->have->property('name', 'brian');
expect(function() {})->to->satisfy('is_callable');
expect(5)->to->be->above(4)
expect($num)->to->be->within(5, 10);
expect('hello')->to->match('/^he/');
?>
View Expect Guide

Assert

<?php
$assert = new Assert();
$assert->typeOf('string', 'hello', 'is string');
$assert->operator(5, '<', 6, 'should be less than');
$assert->isResource(tempfile());
$assert->throws(function() {
    throw new Exception("exception");
}, 'Exception');
?>
View Assert Guide

Leo allows you to make assertions in PHP with an easy to read API. It supports a BDD style expect interface, and an object oriented assert interface.

Leo is also highly extensible. It's a snap to add additional functionality. You can create a language that suits your needs best. See the plugin guide to get started.

Contribute and follow along on GitHub.

Brought to you by the makers of the Peridot BDD testing framework.

Usage

You can install Leo via composer:

composer require peridot-php/leo:~1.0

The expect interface is leveraged via the global function expect.

<?php
expect($actual)->to->equal($expected);
?>

The assert interface can be used via the Assert class.

<?php
use Peridot\Leo\Interfaces\Assert;
$assert = new Assert();
$assert->ok(true);
?>