Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 16b48d6

Browse filesBrowse files
inelgnufabpot
authored andcommitted
add expression request matcher tests
1 parent 09b0a40 commit 16b48d6
Copy full SHA for 16b48d6

File tree

Expand file treeCollapse file tree

1 file changed

+68
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+68
-0
lines changed
+68Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Tests;
13+
14+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
15+
use Symfony\Component\HttpFoundation\ExpressionRequestMatcher;
16+
use Symfony\Component\HttpFoundation\Request;
17+
18+
class ExpressionRequestMatcherTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @expectedException \LogicException
22+
*/
23+
public function testWhenNoExpressionIsSet()
24+
{
25+
$expressionRequestMatcher = new ExpressionRequestMatcher();
26+
$expressionRequestMatcher->matches(new Request());
27+
}
28+
29+
/**
30+
* @dataProvider provideExpressions
31+
*/
32+
public function testMatchesWhenParentMatchesIsTrue($expression, $expected)
33+
{
34+
$request = Request::create('/foo');
35+
$expressionRequestMatcher = new ExpressionRequestMatcher();
36+
37+
$expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
38+
$this->assertSame($expected, $expressionRequestMatcher->matches($request));
39+
}
40+
41+
/**
42+
* @dataProvider provideExpressions
43+
*/
44+
public function testMatchesWhenParentMatchesIsFalse($expression)
45+
{
46+
$request = Request::create('/foo');
47+
$request->attributes->set('foo', 'foo');
48+
$expressionRequestMatcher = new ExpressionRequestMatcher();
49+
$expressionRequestMatcher->matchAttribute('foo', 'bar');
50+
51+
$expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
52+
$this->assertFalse($expressionRequestMatcher->matches($request));
53+
}
54+
55+
public function provideExpressions()
56+
{
57+
return array(
58+
array('request.getMethod() == method', true),
59+
array('request.getPathInfo() == path', true),
60+
array('request.getHost() == host', true),
61+
array('request.getClientIp() == ip', true),
62+
array('request.attributes.all() == attributes', true),
63+
array('request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true),
64+
array('request.getMethod() != method', false),
65+
array('request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false),
66+
);
67+
}
68+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.