【问题标题】:PHPSpec TypeError when checking boolean value检查布尔值时的PHPSpec TypeError
【发布时间】: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 的布尔方法,我将不胜感激。

【问题讨论】:

    标签: symfony phpspec


    【解决方案1】:

    你应该试试$this->supportsClass(get_class($user))->shouldReturn(false).(应该在shouldReturn方法名中小写)

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 2022-01-28
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      • 1970-01-01
      • 2019-04-27
      相关资源
      最近更新 更多