如果预测对象存在于SplObjectStorage中,则测试phpspec问题

时间:2014-03-22 10:20:12

标签: php testing phpspec

任何人都可以向我解释为什么跟随测试没有通过?

正在测试的代码

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

1 个答案:

答案 0 :(得分:0)

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