Question

I have a class with parent call method in it. I want to make sure that parent have been called so that when I edit tested method and remove that line it will fail tests

My class:

public function myMethod($object)
{
    parent::myMethod($object);
    ..
}

My test (spec):

/*
 * @param \Example\Entity\MyEntity $myEntity
 */
function it_cat_call_my_method_example($myEntity)
{
    $this->myMethod($myEntity)->shouldParentHaveBeenCalled(); // what to do here?
}

Is that possible?

Was it helpful?

Solution

This is not possible in the way you describe.

What would the benefit of testing a call to parent be? You presumably want to test whether some behaviour the parent implements happens, so call that directly.

Put another way, if I rewrite my class to not call parent and instead implement the same functionality, I don't think the test should fail.

OTHER TIPS

I don't believe it's possible. PHPSpec lets you test your public API (and calls to collaborators) but not anything to do with inheritance.

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