Skip to content
Snippets Groups Projects
Commit f0c3b571 authored by Larry Garfield's avatar Larry Garfield Committed by Alex Bronstein
Browse files

Make the mock FinalMatcher a real matcher, since it's useful on its own.

parent 7a8d3df9
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -10,6 +10,15 @@
*/
interface FinalMatcherInterface {
/**
* Sets the route collection this matcher should use.
*
* @param RouteCollection $collection
* The collection against which to match.
*
* @return FinalMatcherInterface
* The current matcher.
*/
public function setCollection(RouteCollection $collection);
/**
......
<?php
namespace Drupal\system\Tests\Routing;
namespace Drupal\Core\Routing;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Drupal\Core\Routing\FinalMatcherInterface;
/**
* Mock final matcher for testing.
* Final matcher that simply returns the first item in the remaining routes.
*
* This class simply matches the first remaining route.
*/
class MockFinalMatcher implements FinalMatcherInterface {
class FirstEntryFinalMatcher implements FinalMatcherInterface {
/**
* The RouteCollection this matcher should match against.
*
* @var RouteCollection
*/
protected $routes;
/**
* Sets the route collection this matcher should use.
*
* @param RouteCollection $collection
* The collection against which to match.
*
* @return FinalMatcherInterface
* The current matcher.
*/
public function setCollection(RouteCollection $collection) {
$this->routes = $collection;
......@@ -25,7 +37,7 @@ public function setCollection(RouteCollection $collection) {
public function matchRequest(Request $request) {
// For testing purposes, just return whatever the first route is.
// Return whatever the first route in the collection is.
foreach ($this->routes as $name => $route) {
return array_merge($this->mergeDefaults(array(), $route->getDefaults()), array('_route' => $name));
}
......
......@@ -15,6 +15,7 @@
use Drupal\simpletest\UnitTestBase;
use Drupal\Core\Routing\HttpMethodMatcher;
use Drupal\Core\Routing\NestedMatcher;
use Drupal\Core\Routing\FirstEntryFinalMatcher;
use Exception;
......@@ -74,7 +75,7 @@ public function testNestedMatcher() {
$matcher->setInitialMatcher(new MockPathMatcher($this->fixtures->sampleRouteCollection()));
$matcher->addPartialMatcher(new HttpMethodMatcher());
$matcher->setFinalMatcher(new MockFinalMatcher());
$matcher->setFinalMatcher(new FirstEntryFinalMatcher());
$request = Request::create('/path/one', 'GET');
......
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