forked from symfony/http-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpressionRequestMatcherTest.php
70 lines (61 loc) · 2.5 KB
/
ExpressionRequestMatcherTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpFoundation\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
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();
$expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
$this->assertSame($expected, $expressionRequestMatcher->matches($request));
}
/**
* @dataProvider provideExpressions
*/
public function testMatchesWhenParentMatchesIsFalse($expression)
{
$request = Request::create('/foo');
$request->attributes->set('foo', 'foo');
$expressionRequestMatcher = new ExpressionRequestMatcher();
$expressionRequestMatcher->matchAttribute('foo', 'bar');
$expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
$this->assertFalse($expressionRequestMatcher->matches($request));
}
public function provideExpressions()
{
return [
['request.getMethod() == method', true],
['request.getPathInfo() == path', true],
['request.getHost() == host', true],
['request.getClientIp() == ip', true],
['request.attributes.all() == attributes', true],
['request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true],
['request.getMethod() != method', false],
['request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false],
];
}
}