You are here

public function EntityConverterTest::testConvert in Drupal 8

Same name and namespace in other branches
  1. 9 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 293

Class

EntityConverterTest
@coversDefaultClass \Drupal\Core\ParamConverter\EntityConverter @group ParamConverter @group Entity

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testConvert($value, array $definition, array $defaults, $expected_result) {
  $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));
}