/**
  * @param \Phpro\AnnotatedForms\Event\FormEvent $event
  * @param \Zend\Form\Form $form
  * @param \Phpro\AnnotatedForms\Options\Configuration $configuration
  */
 public function it_should_attach_an_entity_as_object($event, $form, $configuration)
 {
     $event->getTarget()->willReturn($form);
     $event->getConfiguration()->willReturn($configuration);
     $configuration->getEntity()->willReturn('stdClass');
     $form->setObject(Argument::type('stdClass'))->shouldBeCalled();
     $this->setEntityAsObject($event);
 }
 /**
  * Make sure that a form is prepared after loading.
  * This will make sure that collections and input filters are working as suspected.
  *
  * @param FormEvent $e
  */
 public function prepareForm(FormEvent $e)
 {
     $form = $e->getTarget();
     if (!$form instanceof FormInterface) {
         return;
     }
     $form->prepare();
 }
 /**
  * @param FormEvent $e
  */
 public function configureCollectionInputFilter(FormEvent $e)
 {
     $form = $e->getTarget();
     if (!$form instanceof FormInterface) {
         return;
     }
     $this->form = $form;
     $this->handleCollections($form);
 }
 /**
  * @param \Phpro\AnnotatedForms\Event\FormEvent $event
  * @param \Zend\Form\Form $form
  * @param \Zend\Form\Element\Collection $collection
  * @param \Zend\Form\InputFilterProviderFieldset $fieldset
  * @param \Zend\InputFilter\InputFilter $inputFilter
  */
 public function it_should_configure_collection_input_providers($event, $form, $collection, $fieldset, $inputFilter)
 {
     $event->getTarget()->willReturn($form);
     $form->getFieldsets()->willReturn(array($collection));
     $form->getInputFilter()->willReturn($inputFilter);
     $collection->getName()->willReturn('collection');
     $collection->getTargetElement()->willReturn($fieldset);
     $collection->getFieldsets()->willReturn(array($fieldset));
     $fieldset->getFieldsets()->willReturn(array());
     $fieldset->getInputFilterSpecification()->willReturn(array('name' => array('required' => true)));
     $this->configureCollectionInputFilter($event);
     $inputFilter->remove('collection')->shouldHaveBeenCalled();
     $inputFilter->add(Argument::type('Zend\\InputFilter\\CollectionInputFilter'), 'collection')->shouldHaveBeenCalled();
 }
 /**
  * @param FormEvent $e
  */
 public function setEntityAsObject(FormEvent $e)
 {
     $form = $e->getTarget();
     if (!$form instanceof FormInterface) {
         return;
     }
     $config = $e->getConfiguration();
     if (!$config || !$config->getEntity()) {
         return;
     }
     $rc = new \ReflectionClass($config->getEntity());
     $hasConstructorparams = $rc->getConstructor() && $rc->getConstructor()->getNumberOfParameters() ? true : false;
     $instance = $hasConstructorparams ? $rc->newInstanceWithoutConstructor() : $rc->newInstance();
     $form->setObject($instance);
 }
Exemple #6
0
 /**
  * @param       $name
  * @param       $subject
  * @param array $params
  */
 protected function triggerEvent($name, $subject, $params = array())
 {
     $event = FormEvent::create($name, $subject, $this->getConfiguration(), $params);
     $this->getEventManager()->trigger($event);
 }
 /**
  * @param \Phpro\AnnotatedForms\Event\FormEvent $event
  * @param \Zend\Form\Form $form
  */
 public function it_should_prepare_forms($event, $form)
 {
     $event->getTarget()->willReturn($form);
     $this->prepareForm($event);
     $form->prepare()->shouldBeCalled();
 }