give
/
vendor
/
vendor-prefixed
/
symfony
/
http-foundation
/
Tests
/
ExpressionRequestMatcherTest.php
File
2 years ago
Fixtures
2 years ago
Session
2 years ago
schema
2 years ago
AcceptHeaderItemTest.php
2 years ago
AcceptHeaderTest.php
2 years ago
ApacheRequestTest.php
2 years ago
BinaryFileResponseTest.php
2 years ago
CookieTest.php
2 years ago
ExpressionRequestMatcherTest.php
2 years ago
FileBagTest.php
2 years ago
HeaderBagTest.php
2 years ago
IpUtilsTest.php
2 years ago
JsonResponseTest.php
2 years ago
ParameterBagTest.php
2 years ago
RedirectResponseTest.php
2 years ago
RequestMatcherTest.php
2 years ago
RequestStackTest.php
2 years ago
RequestTest.php
2 years ago
ResponseFunctionalTest.php
2 years ago
ResponseHeaderBagTest.php
2 years ago
ResponseTest.php
2 years ago
ResponseTestCase.php
2 years ago
ServerBagTest.php
2 years ago
StreamedResponseTest.php
2 years ago
ExpressionRequestMatcherTest.php
71 lines
| 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 | * Modified by impress-org on 23-January-2024 using Strauss. |
| 12 | * @see https://github.com/BrianHenryIE/strauss |
| 13 | */ |
| 14 | |
| 15 | namespace Give\Vendors\Symfony\Component\HttpFoundation\Tests; |
| 16 | |
| 17 | use PHPUnit\Framework\TestCase; |
| 18 | use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
| 19 | use Give\Vendors\Symfony\Component\HttpFoundation\ExpressionRequestMatcher; |
| 20 | use Give\Vendors\Symfony\Component\HttpFoundation\Request; |
| 21 | |
| 22 | class ExpressionRequestMatcherTest extends TestCase |
| 23 | { |
| 24 | public function testWhenNoExpressionIsSet() |
| 25 | { |
| 26 | $this->expectException('LogicException'); |
| 27 | $expressionRequestMatcher = new ExpressionRequestMatcher(); |
| 28 | $expressionRequestMatcher->matches(new Request()); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @dataProvider provideExpressions |
| 33 | */ |
| 34 | public function testMatchesWhenParentMatchesIsTrue($expression, $expected) |
| 35 | { |
| 36 | $request = Request::create('/foo'); |
| 37 | $expressionRequestMatcher = new ExpressionRequestMatcher(); |
| 38 | |
| 39 | $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression); |
| 40 | $this->assertSame($expected, $expressionRequestMatcher->matches($request)); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @dataProvider provideExpressions |
| 45 | */ |
| 46 | public function testMatchesWhenParentMatchesIsFalse($expression) |
| 47 | { |
| 48 | $request = Request::create('/foo'); |
| 49 | $request->attributes->set('foo', 'foo'); |
| 50 | $expressionRequestMatcher = new ExpressionRequestMatcher(); |
| 51 | $expressionRequestMatcher->matchAttribute('foo', 'bar'); |
| 52 | |
| 53 | $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression); |
| 54 | $this->assertFalse($expressionRequestMatcher->matches($request)); |
| 55 | } |
| 56 | |
| 57 | public function provideExpressions() |
| 58 | { |
| 59 | return [ |
| 60 | ['request.getMethod() == method', true], |
| 61 | ['request.getPathInfo() == path', true], |
| 62 | ['request.getHost() == host', true], |
| 63 | ['request.getClientIp() == ip', true], |
| 64 | ['request.attributes.all() == attributes', true], |
| 65 | ['request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true], |
| 66 | ['request.getMethod() != method', false], |
| 67 | ['request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false], |
| 68 | ]; |
| 69 | } |
| 70 | } |
| 71 |