使用PHPSpec测试父子双向关系
如何使用phpspec测试是否正确创建了父子双向关系 class ParentSpec extends ObjectBehavior { function it_adds_a_reference_to_self_while_(Child $child) { $this->addChild($child); $child->setParent($this)->shouldBeCalled(); } } 类ParentSpec扩展了ObjectBehavior { 函数it_在_(Child$Child)时将_a_引用_添加到_self_ { $this->addChild($child); $child->setParent($this)->应调用(); } }使用PHPSpec测试父子双向关系,php,phpspec,Php,Phpspec,如何使用phpspec测试是否正确创建了父子双向关系 class ParentSpec extends ObjectBehavior { function it_adds_a_reference_to_self_while_(Child $child) { $this->addChild($child); $child->setParent($this)->shouldBeCalled(); } } 类ParentSpec扩展了Objec
第7行抛出一个错误,这是明显的,因为
$this
是一个ParentSpec
对象,而不是Parent
。但是我不知道如何测试调用了setParent
方法。使用getWrappedObject获取底层对象:
$child->setParent($this->getWrappedObject())->shouldBeCalled();