Kahlan Additional Matchers
, (*1)
Installation
via Composer
$ composer require --dev kahlan/extra-matcher
Registration
To manually register the matchers you want, add them in your kahlan-config.php config file like in the following example:, (*2)
use Kahlan\Extra\Matcher\ExtraMatchers;
ExtraMatchers::register(['toBeOneOf', ...]);
Or in case you want to register all matchers, you can simply write:, (*3)
use Kahlan\Extra\Matcher\ExtraMatchers;
ExtraMatchers::register();
Documentation
toBeOneOf($expected) // strict comparison, (*4)
it("passes if $actual is present in $expected", function() {
expect(3)->toBeOneOf([1, 2, 3]);
});
toEqualOneOf($expected) // loose comparison, (*5)
it("passes if $actual is present in $expected", function() {
expect("3")->toEqualOneOf([1, 2, 3]);
});
toImplement($expected) // object implements expected interface, (*6)
namespace App\Spec;
it("passes if $actual implements $expected", function() {
interface Foo { }
class Bar implements Foo {}
$actual = new Bar();
expect($actual)->toImplement('App\Spec\Foo');
});