4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
16 use Symfony\Component\HttpFoundation\ExpressionRequestMatcher;
17 use Symfony\Component\HttpFoundation\Request;
19 class ExpressionRequestMatcherTest extends TestCase
22 * @expectedException \LogicException
24 public function testWhenNoExpressionIsSet()
26 $expressionRequestMatcher = new ExpressionRequestMatcher();
27 $expressionRequestMatcher->matches(new Request());
31 * @dataProvider provideExpressions
33 public function testMatchesWhenParentMatchesIsTrue($expression, $expected)
35 $request = Request::create('/foo');
36 $expressionRequestMatcher = new ExpressionRequestMatcher();
38 $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
39 $this->assertSame($expected, $expressionRequestMatcher->matches($request));
43 * @dataProvider provideExpressions
45 public function testMatchesWhenParentMatchesIsFalse($expression)
47 $request = Request::create('/foo');
48 $request->attributes->set('foo', 'foo');
49 $expressionRequestMatcher = new ExpressionRequestMatcher();
50 $expressionRequestMatcher->matchAttribute('foo', 'bar');
52 $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
53 $this->assertFalse($expressionRequestMatcher->matches($request));
56 public function provideExpressions()
59 array('request.getMethod() == method', true),
60 array('request.getPathInfo() == path', true),
61 array('request.getHost() == host', true),
62 array('request.getClientIp() == ip', true),
63 array('request.attributes.all() == attributes', true),
64 array('request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true),
65 array('request.getMethod() != method', false),
66 array('request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false),