function ChainEntityResolverTest::createEntityResolverMock

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

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 140

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)
            ->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.