Issue #3293284 by catch: Throw an exception when Router::generate() is called

merge-requests/2612/head
Alex Pott 2022-07-04 11:54:21 +01:00
parent 2ba1d67a41
commit c4edefd1d7
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 11 additions and 7 deletions

View File

@ -311,11 +311,15 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf
}
/**
* {@inheritdoc}
* This method is intentionally not implemented. Use
* Drupal\Core\Url instead.
*
* @see https://www.drupal.org/node/2820197
*
* @throws \BadMethodCallException
*/
public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH): string {
@trigger_error(__METHOD__ . '() is deprecated in drupal:8.3.0 and will throw an exception from drupal:10.0.0. Use the \Drupal\Core\Url object instead. See https://www.drupal.org/node/2820197', E_USER_DEPRECATED);
return $this->urlGenerator->generate($name, $parameters, $referenceType);
throw new \BadMethodCallException(__METHOD__ . '() is not supported. Use the \Drupal\Core\Url object instead. See https://www.drupal.org/node/2820197');
}
}

View File

@ -14,13 +14,13 @@ use Prophecy\Argument;
* @group Routing
* @group legacy
*/
class RouterLegacyTest extends UnitTestCase {
class RouterUnsupportedTest extends UnitTestCase {
/**
* @covers ::generate
*/
public function testGenerateDeprecated() {
$this->expectDeprecation('Drupal\Core\Routing\Router::generate() is deprecated in drupal:8.3.0 and will throw an exception from drupal:10.0.0. Use the \Drupal\Core\Url object instead. See https://www.drupal.org/node/2820197');
public function testGenerateUnsupported() {
$this->expectException(\BadMethodCallException::class);
$route_provider = $this->prophesize(RouteProviderInterface::class);
$current_path_stack = $this->prophesize(CurrentPathStack::class);
$url_generator = $this->prophesize(UrlGeneratorInterface::class);
@ -30,7 +30,7 @@ class RouterLegacyTest extends UnitTestCase {
->generate($route_name, Argument::any(), Argument::any())
->willReturn($route_path);
$router = new Router($route_provider->reveal(), $current_path_stack->reveal(), $url_generator->reveal());
$this->assertEquals($route_path, $router->generate($route_name));
$router->generate($route_name);
}
}