MockMatcher.php

Same filename in other branches
  1. 9 core/modules/system/tests/src/Functional/Routing/MockMatcher.php
  2. 10 core/modules/system/tests/src/Functional/Routing/MockMatcher.php
  3. 11.x core/modules/system/tests/src/Functional/Routing/MockMatcher.php

Namespace

Drupal\Tests\system\Functional\Routing

File

core/modules/system/tests/src/Functional/Routing/MockMatcher.php

View source
<?php

namespace Drupal\Tests\system\Functional\Routing;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;

/**
 * A mock matcher that can be configured with any matching logic for testing.
 */
class MockMatcher implements RequestMatcherInterface {
    
    /**
     * The matcher being tested.
     */
    protected $matcher;
    
    /**
     * Constructs a MockMatcher object.
     *
     * @param \Closure $matcher
     *   An anonymous function that will be used for the matchRequest() method.
     */
    public function __construct(\Closure $matcher) {
        $this->matcher = $matcher;
    }
    
    /**
     * {@inheritdoc}
     */
    public function matchRequest(Request $request) {
        $matcher = $this->matcher;
        return $matcher($request);
    }

}

Classes

Title Deprecated Summary
MockMatcher A mock matcher that can be configured with any matching logic for testing.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.