You are here

class ExpressionRequestMatcherTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/ExpressionRequestMatcherTest.php \Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest

Hierarchy

  • class \Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest extends \Symfony\Component\HttpFoundation\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of ExpressionRequestMatcherTest

File

vendor/symfony/http-foundation/Tests/ExpressionRequestMatcherTest.php, line 18

Namespace

Symfony\Component\HttpFoundation\Tests
View source
class ExpressionRequestMatcherTest extends \PHPUnit_Framework_TestCase {

  /**
   * @expectedException \LogicException
   */
  public function testWhenNoExpressionIsSet() {
    $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 array(
      array(
        'request.getMethod() == method',
        true,
      ),
      array(
        'request.getPathInfo() == path',
        true,
      ),
      array(
        'request.getHost() == host',
        true,
      ),
      array(
        'request.getClientIp() == ip',
        true,
      ),
      array(
        'request.attributes.all() == attributes',
        true,
      ),
      array(
        'request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip &&  request.attributes.all() == attributes',
        true,
      ),
      array(
        'request.getMethod() != method',
        false,
      ),
      array(
        'request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip &&  request.attributes.all() == attributes',
        false,
      ),
    );
  }

}

Members