Skip to content

Commit 3e7da99

Browse files
committed
minor symfony#10322 [HttpFoundation][Tests] Add expression request matcher tests (inalgnu)
This PR was submitted for the 2.4-dev branch but it was merged into the 2.4 branch instead (closes symfony#10322). Discussion ---------- [HttpFoundation][Tests] Add expression request matcher tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 76fe21d [HttpFoundation][Tests] add expression request matcher tests
2 parents 09b0a40 + 16b48d6 commit 3e7da99

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy