function UuidResolverTest::testResolveWithEntity

Same name in other branches
  1. 9 core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\UuidResolverTest::testResolveWithEntity()
  2. 8.9.x core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\UuidResolverTest::testResolveWithEntity()
  3. 10 core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\UuidResolverTest::testResolveWithEntity()

Tests resolve() when a UUID corresponds to an entity.

File

core/modules/serialization/tests/src/Unit/EntityResolver/UuidResolverTest.php, line 91

Class

UuidResolverTest
@coversDefaultClass \Drupal\serialization\EntityResolver\UuidResolver @group serialization

Namespace

Drupal\Tests\serialization\Unit\EntityResolver

Code

public function testResolveWithEntity() : void {
    $uuid = '392eab92-35c2-4625-872d-a9dab4da008e';
    $entity = $this->createMock('Drupal\\Core\\Entity\\EntityInterface');
    $entity->expects($this->once())
        ->method('id')
        ->willReturn(1);
    $this->entityRepository
        ->expects($this->once())
        ->method('loadEntityByUuid')
        ->with('test_type', $uuid)
        ->willReturn($entity);
    $normalizer = $this->createMock('Drupal\\serialization\\EntityResolver\\UuidReferenceInterface');
    $normalizer->expects($this->once())
        ->method('getUuid')
        ->with([])
        ->willReturn($uuid);
    $this->assertSame(1, $this->resolver
        ->resolve($normalizer, [], 'test_type'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.