Skip to content
Snippets Groups Projects
Verified Commit c4edefd1 authored by Alex Pott's avatar Alex Pott
Browse files

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

parent 2ba1d67a
No related branches found
No related tags found
No related merge requests found
......@@ -311,11 +311,15 @@ public function getRouteCollection(): RouteCollection {
}
/**
* {@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');
}
}
......@@ -14,13 +14,13 @@
* @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 @@ public function testGenerateDeprecated() {
->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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment