/** * {@inheritdoc} */ public function preSet(FormEvent $event) { $mailbox = $event->getForm()->getRoot()->getData(); if ($mailbox instanceof Mailbox) { $organization = $mailbox->getOrganization(); $this->organization = $organization; } parent::preSet($event); }
/** * @dataProvider entityProvider */ public function testPreSet($entity, $shouldSetData) { $eventMock = $this->getMockBuilder('Symfony\\Component\\Form\\FormEvent')->disableOriginalConstructor()->getMock(); $parentFormMock = $this->getMockForAbstractClass('Symfony\\Component\\Form\\Test\\FormInterface'); $parentFormMock->expects($this->once())->method('getData')->will($this->returnValue($entity)); $formMock = $this->getMockForAbstractClass('Symfony\\Component\\Form\\Test\\FormInterface'); $formMock->expects($this->once())->method('getParent')->will($this->returnValue($parentFormMock)); $eventMock->expects($this->once())->method('getForm')->will($this->returnValue($formMock)); if ($shouldSetData) { $this->taggableHelper->expects($this->once())->method('isTaggable')->willReturn(true); $this->manager->expects($this->once())->method('getPreparedArray')->with($entity)->will($this->returnValue(array(array('owner' => false), array('owner' => true)))); $eventMock->expects($this->exactly($shouldSetData))->method('setData'); } else { $this->manager->expects($this->never())->method('getPreparedArray'); $eventMock->expects($this->never())->method('setData'); } $this->subscriber->preSet($eventMock); }