TYPO3 CMS  TYPO3_8-7
ServerRequestTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
26 class ServerRequestTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
31  protected $request;
32 
33  protected function setUp()
34  {
35  $this->request = new ServerRequest();
36  }
37 
42  {
43  $this->assertEmpty($this->request->getServerParams());
44  }
45 
50  {
51  $this->assertEmpty($this->request->getQueryParams());
52  }
53 
58  {
59  $value = ['foo' => 'bar'];
60  $request = $this->request->withQueryParams($value);
61  $this->assertNotSame($this->request, $request);
62  $this->assertEquals($value, $request->getQueryParams());
63  }
64 
69  {
70  $this->assertEmpty($this->request->getCookieParams());
71  }
72 
77  {
78  $value = ['foo' => 'bar'];
79  $request = $this->request->withCookieParams($value);
80  $this->assertNotSame($this->request, $request);
81  $this->assertEquals($value, $request->getCookieParams());
82  }
83 
88  {
89  $this->assertEmpty($this->request->getUploadedFiles());
90  }
91 
96  {
97  $this->assertEmpty($this->request->getParsedBody());
98  }
99 
104  {
105  $value = ['foo' => 'bar'];
106  $request = $this->request->withParsedBody($value);
107  $this->assertNotSame($this->request, $request);
108  $this->assertEquals($value, $request->getParsedBody());
109  }
110 
115  {
116  $this->assertEmpty($this->request->getAttributes());
117  }
118 
123  {
124  $request = $this->request->withAttribute('foo', 'bar');
125  $this->assertNotSame($this->request, $request);
126  $this->assertEquals('bar', $request->getAttribute('foo'));
127 
128  return $request;
129  }
130 
135  {
137  $new = $request->withoutAttribute('foo');
138  $this->assertNotSame($request, $new);
139  $this->assertNull($new->getAttribute('foo', null));
140  }
141 
146  {
147  $server = [
148  'foo' => 'bar',
149  'baz' => 'bat',
150  ];
151 
152  $server['server'] = true;
153 
154  $files = [
155  'files' => new UploadedFile('php://temp', 0, 0),
156  ];
157 
158  $uri = new Uri('http://example.com');
159  $method = 'POST';
160  $headers = [
161  'host' => ['example.com'],
162  ];
163 
164  $request = new ServerRequest(
165  $uri,
166  $method,
167  'php://memory',
168  $headers,
169  $server,
170  $files
171  );
172 
173  $this->assertEquals($server, $request->getServerParams());
174  $this->assertEquals($files, $request->getUploadedFiles());
175 
176  $this->assertSame($uri, $request->getUri());
177  $this->assertEquals($method, $request->getMethod());
178  $this->assertEquals($headers, $request->getHeaders());
179 
180  $body = $request->getBody();
181  $r = new \ReflectionProperty($body, 'stream');
182  $r->setAccessible(true);
183  $stream = $r->getValue($body);
184  $this->assertEquals('php://memory', $stream);
185  }
186 }