You are here

protected function ChainEntityResolverTest::createEntityResolverMock in Drupal 10

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

Creates a mock entity resolver.

Parameters

null|int $return: Whether the mocked resolve method should return TRUE or FALSE.

bool $called: Whether or not the resolve method is expected to be called.

Return value

\Drupal\serialization\EntityResolver\EntityResolverInterface|\PHPUnit\Framework\MockObject\MockObject The mocked entity resolver.

5 calls to ChainEntityResolverTest::createEntityResolverMock()
ChainEntityResolverTest::testResolverWithFirstResolved in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
Tests the resolve method with a matching resolver first.
ChainEntityResolverTest::testResolverWithLastResolved in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
Tests the resolve method with a matching resolver last.
ChainEntityResolverTest::testResolverWithNoneResolved in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
Tests the resolve method with no matching resolvers.
ChainEntityResolverTest::testResolverWithNoneResolvedUsingAddResolver in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
Tests the resolve method with no matching resolvers, using addResolver.
ChainEntityResolverTest::testResolverWithResolvedToZero in core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php
Tests the resolve method where one resolver returns 0.

File

core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php, line 136

Class

ChainEntityResolverTest
@coversDefaultClass \Drupal\serialization\EntityResolver\ChainEntityResolver @group serialization

Namespace

Drupal\Tests\serialization\Unit\EntityResolver

Code

protected function createEntityResolverMock($return = NULL, $called = TRUE) {
  $mock = $this
    ->createMock('Drupal\\serialization\\EntityResolver\\EntityResolverInterface');
  if ($called) {
    $mock
      ->expects($this
      ->once())
      ->method('resolve')
      ->with($this->testNormalizer, $this->testData, $this->testEntityType)
      ->will($this
      ->returnValue($return));
  }
  else {
    $mock
      ->expects($this
      ->never())
      ->method('resolve');
  }
  return $mock;
}