/** * Sets parent channel * * @param CircularReferenceEntity $parent parent * @return CircularReferenceEntity */ public function setParent(CircularReferenceEntity $parent = null) { if ($this->Parent !== $parent) { if (!is_null($this->Parent)) { $this->Parent->removeChild($this); } if (!is_null($parent)) { $parent->addChild($this); } $this->Parent = $parent; } return $this; }
/** * Testing circular reference * * @return void */ public function testCircularReferenceFatalErrorOnGetParents() { $this->context->expects($this->once())->method('addViolationAt')->with('Parent', sprintf('You cannot set object #%s as parent for object #%s because of circular reference', 'test2', 'test1')); $channel1 = new CircularReferenceEntity(); $channel1->setIds(array('id' => 'test1')); $channel2 = new CircularReferenceEntity(); $channel2->setIds(array('id' => 'test2')); $channel3 = new CircularReferenceEntity(); $channel3->setIds(array('id' => 'test3')); $constraint = new CircularReference(); /* * Validation should go after each item * because we don't have batch update * operations for now */ $channel2->setParent($channel1); $this->validator->validate($channel2, $constraint); $channel1->setParent($channel2); $this->validator->validate($channel1, $constraint); $channel3->setParent($channel2); $this->validator->validate($channel3, $constraint); }