/**
  * {@inheritdoc}
  */
 public function validate(Form $form)
 {
     // first build the form
     $this->errorCollection->reset();
     $this->buildForm($form);
     $this->validated = false;
     // check pre conditions first
     if ($this->getTransition()->checkPreCondition($this->item, $this->context, $this->errorCollection)) {
         $this->validated = true;
         // validate form input now
         if ($this->isInputRequired()) {
             $this->validated = $this->getForm()->validate();
             if (!$this->validated) {
                 $this->errorCollection->addError('transition.validate.form.failed', array(), $form->getErrorCollection());
             }
         }
         // check conditions after validating the form so that context is setup
         if ($this->validated && !$this->getTransition()->checkCondition($this->item, $this->context, $this->errorCollection)) {
             $this->validated = false;
         }
     }
     // trigger the listener, no matter if validated so far
     $this->validated = $this->listener->onValidate($form, $this->validated, $this->workflow, $this->item, $this->context, $this->getTransition()->getName());
     return $this->validated;
 }
 function it_transits_to_next_state(Form $form, Transition $transition, Item $item, Listener $listener, State $state)
 {
     $listener->onBuildForm(Argument::cetera())->shouldBeCalled();
     $listener->onValidate(Argument::cetera())->willReturn(true);
     $listener->onPreTransit(Argument::cetera())->shouldBeCalled();
     $listener->onPostTransit(Argument::cetera())->shouldBeCalled();
     $item->transit($transition, Argument::type(static::CONTEXT_CLASS), Argument::type(static::ERROR_COLLECTION_CLASS), true)->shouldBeCalled()->willReturn($state);
     $transition->executeActions($item, Argument::type(static::CONTEXT_CLASS), Argument::type(static::ERROR_COLLECTION_CLASS))->willReturn(true)->shouldBeCalled();
     $transition->executePostActions($item, Argument::type(static::CONTEXT_CLASS), Argument::type(static::ERROR_COLLECTION_CLASS))->willReturn(true)->shouldBeCalled();
     $transition->buildForm($form, $item)->shouldBeCalled();
     $transition->checkPreCondition($item, Argument::type(static::CONTEXT_CLASS), Argument::type(static::ERROR_COLLECTION_CLASS))->shouldBeCalled();
     $this->validate($form);
     $this->transit()->shouldHaveType('Netzmacht\\Workflow\\Flow\\State');
 }