Example #1
0
 /**
  * Creates a new entity
  *
  * @param Create $command
  */
 public function handle(Create $command)
 {
     $entityClass = $command->getEntityClass();
     $entity = $this->instantiator->instantiate($entityClass);
     $data = $command->getData();
     // UGLY WORKAROUND BEGINS
     $data = array_merge($this->hydrator->extract($entity), $data);
     // UGLY WORKAROUND ENDS
     $this->hydrator->hydrate($entity, $data);
     $this->em->persist($entity);
     $this->em->flush();
 }
Example #2
0
 function it_handles_a_create_command(Entity $entity, Create $command, InstantiatorInterface $instantiator, Hydrator $hydra, EntityManagerInterface $em)
 {
     $entityClass = 'Indigo\\Crud\\Stub\\Entity';
     $data = ['estimatedEnd' => 'now'];
     $command->getEntityClass()->willReturn($entityClass);
     $command->getData()->willReturn($data);
     $instantiator->instantiate($entityClass)->willReturn($entity);
     $hydra->extract($entity)->willReturn([]);
     $hydra->hydrate($entity, $data)->shouldBeCalled();
     $em->persist($entity)->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $this->handle($command);
 }