Question

Can anyone explain to me why the follow test isn't passing?

Code under test

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

phpspec test

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

Solution

If you check the class of $s in it_should_check_if_it_exists() in the test, it's PhpSpec\Wrapper\Collaborator, but $obj in doesItExist() in the subject is Double\stdClass\P1. Obviously PHPSpec is making a double of \StdClass when it's passed to the matcher, so it's not the same object as the one that you have added to the \SplObjectStorage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top