ExpressionRequestMatcher example

use Symfony\Component\HttpFoundation\ExpressionRequestMatcher;
use Symfony\Component\HttpFoundation\Request;

/** * @group legacy */
class ExpressionRequestMatcherTest extends TestCase
{
    public function testWhenNoExpressionIsSet()
    {
        $this->expectException(\LogicException::class);
        $expressionRequestMatcher = new ExpressionRequestMatcher();
        $expressionRequestMatcher->matches(new Request());
    }

    /** * @dataProvider provideExpressions */
    public function testMatchesWhenParentMatchesIsTrue($expression$expected)
    {
        $request = Request::create('/foo');
        $expressionRequestMatcher = new ExpressionRequestMatcher();

        
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcher\ExpressionRequestMatcher;

class ExpressionRequestMatcherTest extends TestCase
{
    /** * @dataProvider provideExpressions */
    public function testMatchesWhenParentMatchesIsTrue($expression$expected)
    {
        $request = Request::create('/foo');
        $expressionRequestMatcher = new ExpressionRequestMatcher(new ExpressionLanguage()$expression);
        $this->assertSame($expected$expressionRequestMatcher->matches($request));
    }

    public static function provideExpressions()
    {
        return [
            ['request.getMethod() == method', true],
            ['request.getPathInfo() == path', true],
            ['request.getHost() == host', true],
            ['request.getClientIp() == ip', true],
            ['request.attributes.all() == attributes', true],
            [
Home | Imprint | This part of the site doesn't use cookies.