You are here

public function RequestTest::testCreateCheckPrecedence in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Tests/RequestTest.php \Symfony\Component\HttpFoundation\Tests\RequestTest::testCreateCheckPrecedence()

@covers Symfony\Component\HttpFoundation\Request::create

File

vendor/symfony/http-foundation/Tests/RequestTest.php, line 246

Class

RequestTest

Namespace

Symfony\Component\HttpFoundation\Tests

Code

public function testCreateCheckPrecedence() {

  // server is used by default
  $request = Request::create('/', 'DELETE', array(), array(), array(), array(
    'HTTP_HOST' => 'example.com',
    'HTTPS' => 'on',
    'SERVER_PORT' => 443,
    'PHP_AUTH_USER' => 'fabien',
    'PHP_AUTH_PW' => 'pa$$',
    'QUERY_STRING' => 'foo=bar',
    'CONTENT_TYPE' => 'application/json',
  ));
  $this
    ->assertEquals('example.com', $request
    ->getHost());
  $this
    ->assertEquals(443, $request
    ->getPort());
  $this
    ->assertTrue($request
    ->isSecure());
  $this
    ->assertEquals('fabien', $request
    ->getUser());
  $this
    ->assertEquals('pa$$', $request
    ->getPassword());
  $this
    ->assertEquals('', $request
    ->getQueryString());
  $this
    ->assertEquals('application/json', $request->headers
    ->get('CONTENT_TYPE'));

  // URI has precedence over server
  $request = Request::create('http://thomas:pokemon@example.net:8080/?foo=bar', 'GET', array(), array(), array(), array(
    'HTTP_HOST' => 'example.com',
    'HTTPS' => 'on',
    'SERVER_PORT' => 443,
  ));
  $this
    ->assertEquals('example.net', $request
    ->getHost());
  $this
    ->assertEquals(8080, $request
    ->getPort());
  $this
    ->assertFalse($request
    ->isSecure());
  $this
    ->assertEquals('thomas', $request
    ->getUser());
  $this
    ->assertEquals('pokemon', $request
    ->getPassword());
  $this
    ->assertEquals('foo=bar', $request
    ->getQueryString());
}