public function testResourceSetCanGetAResourceChild() { $resource1 = new Resource(); $this->resourceSet->addChild($resource1); $this->assertEquals($resource1, $this->resourceSet->getResource($resource1->getId())); $this->tester->assertThrows(function () { $this->resourceSet->getResource('reallyInvalidId'); }, 'Exception', 'An exception as to be thrown.'); }
/** * @param $entity * @param ClassMetadata $metadata * * @return ResourceSet * @throws Exception */ public function getEmbeddedRelations($entity, ClassMetadata $metadata) { $relations = new ResourceSet(); $relationsMeta = $metadata->getAssociationMappings(); $relationsClass = []; foreach ($relationsMeta as $relationMeta) { $getter = 'get' . ucfirst($relationMeta['fieldName']); // We're getting the embedded classes try { $relationsClass[$relationMeta['fieldName']] = $entity->{$getter}(); } catch (Throwable $e) { throw new Exception(sprintf('The method %s does not exist.', $getter)); } } foreach ($relationsClass as $relationClass) { $relationMetaData = $this->entityManager->getClassMetadata(get_class($relationClass)); $relations->addChild($this->createResource($relationMetaData, $relationClass)); } return $relations; }