function ChainEntityResolverTest::createEntityResolverMock

Same name and namespace in other branches
  1. 11.x core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\ChainEntityResolverTest::createEntityResolverMock()
  2. 10 core/modules/serialization/tests/src/Unit/EntityResolver/ChainEntityResolverTest.php \Drupal\Tests\serialization\Unit\EntityResolver\ChainEntityResolverTest::createEntityResolverMock()
  3. 8.9.x 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.

File

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

Class

ChainEntityResolverTest
@coversDefaultClass \Drupal\serialization\EntityResolver\ChainEntityResolver[[api-linebreak]] @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)
      ->willReturn($return);
  }
  else {
    $mock->expects($this->never())
      ->method('resolve');
  }
  return $mock;
}

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