Verified Commit 678fdc7f authored by Alex Pott's avatar Alex Pott
Browse files

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

(cherry picked from commit c4edefd1)
parent 78ac39a5
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -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');
  }

}
+4 −4
Original line number Diff line number Diff line
@@ -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);
  }

}