function ParamConverterManagerTest::testConvertMissingParam

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testConvertMissingParam()
  2. 8.9.x core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testConvertMissingParam()
  3. 11.x core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php \Drupal\Tests\Core\ParamConverter\ParamConverterManagerTest::testConvertMissingParam()

@covers ::convert

File

core/tests/Drupal/Tests/Core/ParamConverter/ParamConverterManagerTest.php, line 226

Class

ParamConverterManagerTest
@coversDefaultClass \Drupal\Core\ParamConverter\ParamConverterManager @group ParamConverter

Namespace

Drupal\Tests\Core\ParamConverter

Code

public function testConvertMissingParam() : void {
    $route = new Route('/test/{id}');
    $parameters = [
        'id' => [
            'converter' => 'test_convert',
        ],
    ];
    $route->setOption('parameters', $parameters);
    $defaults = [
        RouteObjectInterface::ROUTE_OBJECT => $route,
        RouteObjectInterface::ROUTE_NAME => 'test_route',
        'id' => 1,
    ];
    $converter = $this->createMock('Drupal\\Core\\ParamConverter\\ParamConverterInterface');
    $converter->expects($this->any())
        ->method('convert')
        ->with(1, $this->isType('array'), 'id', $this->isType('array'))
        ->willReturn(NULL);
    $this->manager
        ->addConverter($converter, 'test_convert');
    $this->expectException(ParamNotConvertedException::class);
    $this->expectExceptionMessage('The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")');
    $this->manager
        ->convert($defaults);
}

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