joshuahornby's avatar

PhpSpec seems to be stopping through test suite

I am just starting to use PhpSpec and I seem to be running into an issue

I am testing this function

public function response(array $errors)
{
    return $this->errorForbidden($errors);
}

public function errorForbidden($message = 'Forbidden')
{
     return $this->setStatusCode(403)->respondWithError($message);
}

When I run this test

function it_checks_errors_returns_array_of_errors()
{
    $error = ["This is an error" => "Error time!"];

    $this->response($error)->shouldBeCalled();
}

it just stops half way through, see the image:

http://cl.ly/image/0K2v2r0d290l

Where as I should see something like this:

http://cl.ly/image/2X1G1e1T2N1q

There must be a simple reason why this is happening I just don't know it

0 likes
2 replies
RayRutjes's avatar

shouldBeCalled() must only be used with mocked objects and must not be used with the actual class your testing. Could you give us more context of your class and explain your intention ?

joshuahornby's avatar

I just want to test what is returned is an actual array. Is there a good cheat sheet with all the relevant methods when testing classes?

Please or to participate in this conversation.