function it_returns_null_when_no_entity_found(Load $query, EntityRepository $repository, EntityManagerInterface $em) { $query->getEntityClass()->willReturn('Indigo\\Crud\\Stub\\Entity'); $query->getId()->willReturn(1); $repository->find(1)->willReturn(null); $em->getRepository('Indigo\\Crud\\Stub\\Entity')->willReturn($repository); $this->handle($query)->shouldReturn(null); }
/** * Returns an entity's data * * @param Load $query * * @return array|null */ public function handle(Load $query) { $entityClass = $query->getEntityClass(); $id = $query->getId(); $entity = $this->em->getRepository($entityClass)->find($id); if ($entity) { return $this->hydrator->extract($entity); } }