You are here

public function DiactorosFactoryTest::testCreateRequest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/psr-http-message-bridge/Tests/Factory/DiactorosFactoryTest.php \Symfony\Bridge\PsrHttpMessage\Tests\Factory\DiactorosFactoryTest::testCreateRequest()

File

vendor/symfony/psr-http-message-bridge/Tests/Factory/DiactorosFactoryTest.php, line 40

Class

DiactorosFactoryTest
@author Kévin Dunglas <dunglas@gmail.com>

Namespace

Symfony\Bridge\PsrHttpMessage\Tests\Factory

Code

public function testCreateRequest() {
  $stdClass = new \stdClass();
  $request = new Request(array(
    'foo' => '1',
    'bar' => array(
      'baz' => '42',
    ),
  ), array(
    'twitter' => array(
      '@dunglas' => 'Kévin Dunglas',
      '@coopTilleuls' => 'Les-Tilleuls.coop',
    ),
    'baz' => '2',
  ), array(
    'a1' => $stdClass,
    'a2' => array(
      'foo' => 'bar',
    ),
  ), array(
    'c1' => 'foo',
    'c2' => array(
      'c3' => 'bar',
    ),
  ), array(
    'f1' => $this
      ->createUploadedFile('F1', 'f1.txt', 'text/plain', UPLOAD_ERR_OK),
    'foo' => array(
      'f2' => $this
        ->createUploadedFile('F2', 'f2.txt', 'text/plain', UPLOAD_ERR_OK),
    ),
  ), array(
    'REQUEST_METHOD' => 'POST',
    'HTTP_HOST' => 'dunglas.fr',
    'HTTP_X_SYMFONY' => '2.8',
  ), 'Content');
  $psrRequest = $this->factory
    ->createRequest($request);
  $this
    ->assertEquals('Content', $psrRequest
    ->getBody()
    ->__toString());
  $queryParams = $psrRequest
    ->getQueryParams();
  $this
    ->assertEquals('1', $queryParams['foo']);
  $this
    ->assertEquals('42', $queryParams['bar']['baz']);
  $parsedBody = $psrRequest
    ->getParsedBody();
  $this
    ->assertEquals('Kévin Dunglas', $parsedBody['twitter']['@dunglas']);
  $this
    ->assertEquals('Les-Tilleuls.coop', $parsedBody['twitter']['@coopTilleuls']);
  $this
    ->assertEquals('2', $parsedBody['baz']);
  $attributes = $psrRequest
    ->getAttributes();
  $this
    ->assertEquals($stdClass, $attributes['a1']);
  $this
    ->assertEquals('bar', $attributes['a2']['foo']);
  $cookies = $psrRequest
    ->getCookieParams();
  $this
    ->assertEquals('foo', $cookies['c1']);
  $this
    ->assertEquals('bar', $cookies['c2']['c3']);
  $uploadedFiles = $psrRequest
    ->getUploadedFiles();
  $this
    ->assertEquals('F1', $uploadedFiles['f1']
    ->getStream()
    ->__toString());
  $this
    ->assertEquals('f1.txt', $uploadedFiles['f1']
    ->getClientFilename());
  $this
    ->assertEquals('text/plain', $uploadedFiles['f1']
    ->getClientMediaType());
  $this
    ->assertEquals(UPLOAD_ERR_OK, $uploadedFiles['f1']
    ->getError());
  $this
    ->assertEquals('F2', $uploadedFiles['foo']['f2']
    ->getStream()
    ->__toString());
  $this
    ->assertEquals('f2.txt', $uploadedFiles['foo']['f2']
    ->getClientFilename());
  $this
    ->assertEquals('text/plain', $uploadedFiles['foo']['f2']
    ->getClientMediaType());
  $this
    ->assertEquals(UPLOAD_ERR_OK, $uploadedFiles['foo']['f2']
    ->getError());
  $serverParams = $psrRequest
    ->getServerParams();
  $this
    ->assertEquals('POST', $serverParams['REQUEST_METHOD']);
  $this
    ->assertEquals('2.8', $serverParams['HTTP_X_SYMFONY']);
  $this
    ->assertEquals('POST', $psrRequest
    ->getMethod());
  $this
    ->assertEquals(array(
    '2.8',
  ), $psrRequest
    ->getHeader('X-Symfony'));
}