function EntityConverterTest::testConvert

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php \Drupal\Tests\Core\ParamConverter\EntityConverterTest::testConvert()
  2. 8.9.x core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php \Drupal\Tests\Core\ParamConverter\EntityConverterTest::testConvert()
  3. 10 core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php \Drupal\Tests\Core\ParamConverter\EntityConverterTest::testConvert()

Tests the convert() method.

@dataProvider providerTestConvert

@covers ::convert

File

core/tests/Drupal/Tests/Core/ParamConverter/EntityConverterTest.php, line 182

Class

EntityConverterTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21ParamConverter%21EntityConverter.php/class/EntityConverter/11.x" title="Parameter converter for upcasting entity IDs to full objects." class="local">\Drupal\Core\ParamConverter\EntityConverter</a> @group ParamConverter @group Entity

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testConvert($value, array $definition, array $defaults, $expected_result) : void {
    $this->setUpMocks();
    $this->entityRepository
        ->expects($this->any())
        ->method('getCanonical')
        ->willReturnCallback(function ($entity_type_id, $entity_id) {
        return $entity_type_id === 'entity_test' && $entity_id === 'valid_id' ? (object) [
            'id' => 'valid_id',
        ] : NULL;
    });
    $this->assertEquals($expected_result, $this->entityConverter
        ->convert($value, $definition, 'foo', $defaults));
}

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