bravesheep/phpspec-expect

此软件包已被废弃,不再维护。未建议替代软件包。

添加期望函数以支持BDD风格断言

v0.2.0 2019-07-25 13:36 UTC

This package is auto-updated.

Last update: 2023-06-29 10:29:51 UTC


README

为您的代码添加 expect(value) 函数,允许您使用与 phpspec 相同的断言风格。请注意,phpspec 使用 should[matcher]shouldNot[matcher],而此函数也允许 to[matcher]notTo[matcher] 调用。有关匹配器的更多信息,请参阅 phpspec 匹配器文档

全局添加自定义匹配器

通过调用 Bravesheep\PhpspecExpect\ContainerHolder::getInstance()->getContainer(),您可以修改 phpspec ServiceContainer 实例。从那一刻起,您可以通过添加以 matchers.matcher 开头的对象为所有测试添加额外的匹配器,例如

$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'));
});

请注意,共享对象只会创建一次,而那些使用 $container->set() 添加的对象将在每次调用时重新构造。

MatchersProviderInterface

如果执行 expect(value) 调用的对象实现了 PhpSpec\Matcher\MatchersProviderInterface,则该对象提供的匹配器将包含在可用匹配器中。