2

How to test with phpspec that parent-child biedirectional relations are created properly?

class ParentSpec extends ObjectBehavior
{
    function it_adds_a_reference_to_self_while_(Child $child)
    {
        $this->addChild($child);

        $child->setParent($this)->shouldBeCalled();
    }
}

Line 7 throws an error, which is obious because $this is a ParentSpec object not Parent. But I have no other ideas how to test that setParent method has been called.

LNow
  • 68
  • 5

1 Answers1

1

Use getWrappedObject to get the underlying object:

$child->setParent($this->getWrappedObject())->shouldBeCalled();

http://www.phpspec.net/en/latest/cookbook/wrapped-objects.html

dblack
  • 79
  • 8