【发布时间】:2017-09-22 16:39:56
【问题描述】:
我有一个名为 supportsClass 的布尔方法(我知道,但我一直相信 BDD/TDD),它是作为此接口的一部分实现的。
Symfony\Component\Security\Core\User\UserProviderInterface
在我的规范中,我正在像这样测试这种方法
$this->supportsClass(get_class($user))->ShouldReturn(false).
其中用户是先知对象。当我运行我的规范时,我会抛出这个异常
[err:TypeError("传递给 PhpSpec\Exception\ExceptionFactory::methodNotFound() 的参数 1 必须是字符串类型,给定 null
我找不到使用任何 === 或 == 匹配器使此规范通过的方法。我能找到的唯一布尔特定匹配器是这些
$this->shouldBeActive(); // isActive() method should return true
$this->shouldHaveSomething(); // hasSomething() method should return true
$this->shouldNotBeActive(); // isActive() method should return false
$this->shouldNotHaveSomething(); // hasSomething() method should return false
如您所见,被测方法与这两种方法都不匹配。如果有人能阐明如何测试没有 is/has 的布尔方法,我将不胜感激。
【问题讨论】: