sampleRouteCollection example

->method('acquire')
      ->with('router_rebuild')
      ->willReturn(TRUE);

    $routing_fixtures = new RoutingFixtures();
    $routes = $routing_fixtures->staticSampleRouteCollection();

    $this->yamlDiscovery->expects($this->once())
      ->method('findAll')
      ->willReturn(['test_module' => $routes]);

    $route_collection = $routing_fixtures->sampleRouteCollection();
    foreach ($route_collection->all() as $route) {
      $route->setOption('compiler_class', RouteCompiler::class);
    }
    $route_build_event = new RouteBuildEvent($route_collection);

    // Ensure that the alter routes events are fired.     $this->dispatcher->expects($this->atLeast(2))
      ->method('dispatch')
      ->withConsecutive(
        [$route_build_event, RoutingEvents::DYNAMIC],
        [$route_build_event, RoutingEvents::ALTER],
      );

  public function testAcceptFiltering($accept_header$format$included_route$excluded_route) {
    $collection = $this->fixtures->sampleRouteCollection();

    $request = Request::create('path/two', 'GET');
    $request->headers->set('Accept', $accept_header);
    $request->setRequestFormat($format);
    $routes = $this->matcher->filter($collection$request);
    $this->assertCount(4, $routes, 'The correct number of routes was found.');
    $this->assertNotNull($routes->get($included_route), "Route $included_route was found when matching $accept_header.");
    $this->assertNull($routes->get($excluded_route), "Route $excluded_route was not found when matching $accept_header.");
    foreach ($routes as $name => $route) {
      $this->assertEquals($name$included_route, "Route $included_route is the first one in the collection when matching $accept_header.");
      break;
    }
/** * Confirms that we can find routes with the exact incoming path. */
  public function testExactPathMatch() {
    $connection = Database::getConnection();
    $provider = new RouteProvider($connection$this->state, $this->currentPath, $this->cache, $this->pathProcessor, $this->cacheTagsInvalidator, 'test_routes');

    $this->fixtures->createTables($connection);

    $dumper = new MatcherDumper($connection$this->state, $this->logger, 'test_routes');
    $dumper->addRoutes($this->fixtures->sampleRouteCollection());
    $dumper->dump();

    $path = '/path/one';

    $request = Request::create($path, 'GET');

    $routes = $provider->getRouteCollectionForRequest($request);

    foreach ($routes as $route) {
      $this->assertEquals($path$route->getPath(), 'Found path has correct pattern');
    }
  }
$this->fixtures = new RoutingFixtures();
    $this->matcher = new ContentTypeHeaderMatcher();
  }

  /** * Tests that routes are not filtered on safe requests. * * @dataProvider providerTestSafeRequestFilter */
  public function testSafeRequestFilter($method) {
    $collection = $this->fixtures->sampleRouteCollection();
    $collection->addCollection($this->fixtures->contentRouteCollection());

    $request = Request::create('path/two', $method);
    $routes = $this->matcher->filter($collection$request);
    $this->assertCount(7, $routes, 'The correct number of routes was found.');
  }

  public function providerTestSafeRequestFilter() {
    return [
      ['GET'],
      ['HEAD'],
      [
Home | Imprint | This part of the site doesn't use cookies.