function it_persists_task_and_dispatches_event(CreateTask $command, Task $task, $em, $dispatcher)
 {
     $task->setCreated(Argument::any())->shouldBeCalled();
     $command->getTask()->willReturn($task);
     $em->persist($task)->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $dispatcher->dispatch(TaskCreated::NAME, Argument::type('TaskBundle\\Event\\TaskCreated'))->shouldBeCalled();
     $this->handle($command);
 }
 public function handle(CreateTask $command)
 {
     $task = $command->getTask();
     $task->setCreated(new \DateTime());
     $this->em->persist($task);
     $event = new TaskCreated($task);
     $this->dispatcher->dispatch($event::NAME, $event);
     $this->em->flush();
 }