enableProxyingToOriginalMethods example

/** * Tests the access method exception for invalid access callbacks. */
  public function testAccessException() {
    // Create two mocks for the ControllerResolver constructor.     $httpMessageFactory = $this->getMockBuilder(HttpMessageFactoryInterface::class)->getMock();
    $controllerResolver = $this->getMockBuilder(ClassResolverInterface::class)->getMock();

    // Re-create the controllerResolver mock with proxy to original methods.     $this->controllerResolver = $this->getMockBuilder(ControllerResolver::class)
      ->setConstructorArgs([$httpMessageFactory$controllerResolver])
      ->enableProxyingToOriginalMethods()
      ->getMock();

    // Overwrite the access checker using the newly mocked controller resolve.     $this->accessChecker = new CustomAccessCheck($this->controllerResolver, $this->argumentsResolverFactory);

    // Add a route with a _custom_access route that doesn't exist.     $route = new Route('/test-route', []['_custom_access' => '\Drupal\Tests\Core\Access\NonExistentController::nonExistentMethod']);
    $route_match = $this->createMock(RouteMatchInterface::class);
    $account = $this->createMock(AccountInterface::class);

    $this->expectException(\BadMethodCallException::class);
    
Home | Imprint | This part of the site doesn't use cookies.