【问题标题】:phpspec issue with testing if a prophecy object exists within a SplObjectStoragephpspec 测试 SplObjectStorage 中是否存在预言对象的问题
【发布时间】:2014-03-22 10:20:11
【问题描述】:

谁能向我解释为什么后续测试没有通过?

正在测试的代码

public function doesItExist( $obj, $dataSet ){
    if( $dataSet->contains( $obj ) ){
        return true;
    } 
    return false;
}

phpspec 测试

function it_should_check_if_it_exists( \stdClass $s ){
    $dataSet = new \SplObjectStorage();
    $dataSet->attach($s);
    $this->doesItExist( $s, $dataSet )->shouldReturn(true);
}

【问题讨论】:

    标签: php testing phpspec


    【解决方案1】:

    如果在测试中检查it_should_check_if_it_exists()中$s的类是PhpSpec\Wrapper\Collaborator,但是subject中dosItExist()中的$obj是Double\stdClass \P1。显然,当 PHPSpec 传递给匹配器时,它是 \StdClass 的两倍,因此它与您添加到 \SplObjectStorage 的对象不同。

    【讨论】:

      猜你喜欢
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2012-11-05
      • 2011-02-07
      相关资源
      最近更新 更多