function JsonApiDocumentTopLevelNormalizerTest::setUp
Overrides UnitTestCase::setUp
File
- 
              core/
modules/ jsonapi/ tests/ src/ Unit/ Normalizer/ JsonApiDocumentTopLevelNormalizerTest.php, line 38  
Class
- JsonApiDocumentTopLevelNormalizerTest
 - @coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer[[api-linebreak]] @group jsonapi
 
Namespace
Drupal\Tests\jsonapi\Unit\NormalizerCode
public function setUp() : void {
  $resource_type_repository = $this->prophesize(ResourceTypeRepository::class);
  $field_resolver = $this->prophesize(FieldResolver::class);
  $resource_type_repository->getByTypeName(Argument::any())
    ->willReturn(new ResourceType('node', 'article', NULL));
  $entity_storage = $this->prophesize(EntityStorageInterface::class);
  $self = $this;
  $uuid_to_id = [
    '76dd5c18-ea1b-4150-9e75-b21958a2b836' => 1,
    'fcce1b61-258e-4054-ae36-244d25a9e04c' => 2,
  ];
  $entity_storage->loadByProperties(Argument::type('array'))
    ->will(function ($args) use ($self, $uuid_to_id) {
    $result = [];
    foreach ($args[0]['uuid'] as $uuid) {
      $entity = $self->prophesize(EntityInterface::class);
      $entity->uuid()
        ->willReturn($uuid);
      $entity->id()
        ->willReturn($uuid_to_id[$uuid]);
      $result[$uuid] = $entity->reveal();
    }
    return $result;
  });
  $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
  $entity_type_manager->getStorage('node')
    ->willReturn($entity_storage->reveal());
  $entity_type = $this->prophesize(EntityTypeInterface::class);
  $entity_type->getKey('uuid')
    ->willReturn('uuid');
  $entity_type_manager->getDefinition('node')
    ->willReturn($entity_type->reveal());
  $this->normalizer = new JsonApiDocumentTopLevelNormalizer($entity_type_manager->reveal(), $resource_type_repository->reveal(), $field_resolver->reveal());
  $serializer = $this->prophesize(DenormalizerInterface::class);
  $serializer->willImplement(SerializerInterface::class);
  $serializer->denormalize(Argument::type('array'), Argument::type('string'), Argument::type('string'), Argument::type('array'))
    ->willReturnArgument(0);
  $this->normalizer
    ->setSerializer($serializer->reveal());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.