AttributesRequestMatcher example

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcher\AttributesRequestMatcher;
use Symfony\Component\HttpFoundation\Response;

class AttributesRequestMatcherTest extends TestCase
{
    /** * @dataProvider getData */
    public function test(string $key, string $regexp, bool $expected)
    {
        $matcher = new AttributesRequestMatcher([$key => $regexp]);
        $request = Request::create('/admin/foo');
        $request->attributes->set('foo', 'foo_bar');
        $request->attributes->set('_controller', fn () => new Response('foo'));
        $this->assertSame($expected$matcher->matches($request));
    }

    public static function getData(): array
    {
        return [
            ['foo', 'foo_.*', true],
            ['foo', 'foo', true],
            [
Home | Imprint | This part of the site doesn't use cookies.