bravesheep / phpspec-expect
Add the expect function for BDD style assertions
Installs: 2 980
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 1
Open Issues: 1
Requires
- phpspec/phpspec: ~5.1
This package is auto-updated.
Last update: 2023-06-29 10:29:51 UTC
README
Adds the expect(value)
function for you to your code, allowing you the same style of assertions that
phpspec uses. Note that phpspec uses should[matcher]
and shouldNot[matcher]
, where this function also
allows to[matcher]
and notTo[matcher]
calls. For more information of matchers take a look at the
phpspec documentation on matchers.
Adding custom matcher globally
By calling Bravesheep\PhpspecExpect\ContainerHolder::getInstance()->getContainer()
you can modify
the phpspec ServiceContainer instance. You can add extra matchers for all your tests from that point
on by adding an object starting with matchers.matcher
, for example:
$container = \Bravesheep\PhpspecExpect\ContainerHolder::getInstance()->getContainer();
$container->setShared('matchers.matcher.my.custom.matcher', function (\PhpSpec\ServiceContainer $c) {
return new My\Custom\Matcher($c->get('formatter.presenter'));
});
Note that shared objects will only be created once, whereas those added with $container->set()
will be
constructed again for every call made.
MatchersProviderInterface
If the object in which a call to expect(value)
is made implements the PhpSpec\Matcher\MatchersProviderInterface
then the matchers provided by that object are included in the available matchers.