Reputation: 16165
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?
Upvotes: 1
Views: 1265
Reputation: 18848
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.
Upvotes: 3
Reputation: 219
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.
Upvotes: 3