예제 #1
0
 function it_returns_null_if_metadata_is_not_found(RepositoryInterface $metadataContainerRepository, MetadataCompilerInterface $metadataCompiler, MetadataHierarchyProviderInterface $metadataHierarchyProvider, MetadataSubjectInterface $metadataSubject)
 {
     $metadataHierarchyProvider->getHierarchyByMetadataSubject($metadataSubject)->shouldBeCalled()->willReturn(['MetadataSubject-42', 'MetadataSubject']);
     $metadataContainerRepository->findOneBy(['id' => 'MetadataSubject-42'])->shouldBeCalled()->willReturn(null);
     $metadataContainerRepository->findOneBy(['id' => 'MetadataSubject'])->shouldBeCalled()->willReturn(null);
     $metadataCompiler->compile(Argument::cetera())->shouldNotBeCalled();
     $this->findMetadataBySubject($metadataSubject)->shouldReturn(null);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function findMetadataBySubject(MetadataSubjectInterface $metadataSubject)
 {
     $identifiers = $this->metadataHierarchyProvider->getHierarchyByMetadataSubject($metadataSubject);
     $parents = [];
     $baseMetadata = null;
     foreach ($identifiers as $identifier) {
         /** @var MetadataContainerInterface $metadataContainer */
         // TODO: Use find($identifier) after Resource refactoring (PR #2255)
         $metadataContainer = $this->metadataContainerRepository->findOneBy(['id' => $identifier]);
         if (null === $metadataContainer) {
             continue;
         }
         if (null === $baseMetadata) {
             $baseMetadata = $metadataContainer->getMetadata();
             continue;
         }
         $parents[] = $metadataContainer->getMetadata();
     }
     if (null === $baseMetadata) {
         return null;
     }
     return $this->metadataCompiler->compile($baseMetadata, $parents);
 }