jacobstr / esperance
BDD style assertion library for PHP.
Installs: 30 809
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 3
pkg:composer/jacobstr/esperance
Requires
- php: >=5.3.2
- evenement/evenement: ~1.0
- jacobstr/dumpling: ~0.0.3
This package is not auto-updated.
Last update: 2025-11-04 06:37:57 UTC
README
BDD style assertion library for PHP.
Heavily inspired by expect.js.
Usage
Installation
Espérance can be installed using Composer.
At first, save below as composer.json at the root of your project.
{
"require": {
"esperance/esperance": "dev-master"
}
}
And run these commands.
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install
Then Espérance would be installed in ./vendor directory and also ./vendor/autoload.php is generated.
Very minimal testing script by hand
Just define your expect method or function to construt Esperance\Assertion object.
<?php require './vendor/autoload.php'; function expect($obj) { return new \Esperance\Assertion($obj); } expect(1)->to->be(1); echo "All tests passed.", PHP_EOL;
PHPUnit integrtion
Use esperance/esperance-phpunit.
Extension
Extension using event dispatcher is available.
Events
- before_assertion
\Esperance\Assertion->beforeAssertion($callback) - assertion_success
\Esperance\Assertion->onAssertionSuccess($callback) - assertion_failure
\Esperance\Assertion->onAssertionFailure($callback)
Usage
Assertion counter example.
<?php require './vendor/autoload.php'; $count = $success = $failure = 0; function expect($subject) { global $count, $success, $failure; $extension = new \Esperance\Extension; $extension->beforeAssertion(function () use (&$count) { $count++; }); return new \Esperance\Assertion($subject, $extension); } expect(NULL)->to->be(NULL); expect(0)->to->be(0); expect(1)->to->be(1); echo "Count: {$count}", PHP_EOL; // => Count: 3
License
The MIT License
Author
Yuya Takeyama