You are here

public function ContentEntityNormalizerTest::createMockForContentEntity in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::createMockForContentEntity()
  2. 9 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::createMockForContentEntity()

Creates a mock content entity.

Parameters

$definitions: The properties the will be returned.

Return value

\PHPUnit\Framework\MockObject\MockObject

2 calls to ContentEntityNormalizerTest::createMockForContentEntity()
ContentEntityNormalizerTest::testNormalize in core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
Tests the normalize() method.
ContentEntityNormalizerTest::testNormalizeWithAccountContext in core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php
Tests the normalize() method with account context passed.

File

core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php, line 129

Class

ContentEntityNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\ContentEntityNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function createMockForContentEntity($definitions) {
  $content_entity_mock = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')
    ->disableOriginalConstructor()
    ->onlyMethods([
    'getTypedData',
  ])
    ->getMockForAbstractClass();
  $typed_data = $this
    ->prophesize(ComplexDataInterface::class);
  $typed_data
    ->getProperties(TRUE)
    ->willReturn($definitions)
    ->shouldBeCalled();
  $content_entity_mock
    ->expects($this
    ->any())
    ->method('getTypedData')
    ->will($this
    ->returnValue($typed_data
    ->reveal()));
  return $content_entity_mock;
}