1

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

被测代码

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);
}
4

1 回答 1

0

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

于 2014-04-02T05:22:35.117 回答