function EntityConverterTest::testConvert
Tests the convert() method.
@dataProvider providerTestConvert
@covers ::convert
      
    
File
- 
              core/
tests/ Drupal/ Tests/ Core/ ParamConverter/ EntityConverterTest.php, line 182  
Class
- EntityConverterTest
 - @coversDefaultClass \Drupal\Core\ParamConverter\EntityConverter[[api-linebreak]] @group ParamConverter @group Entity
 
Namespace
Drupal\Tests\Core\ParamConverterCode
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.