‪TYPO3CMS  10.4
ServerRequestTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
28 class ‪ServerRequestTest extends UnitTestCase
29 {
33  protected ‪$request;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->request = new ‪ServerRequest();
39  }
40 
44  public function ‪getServerParamsAreEmptyByDefault()
45  {
46  self::assertEmpty($this->request->getServerParams());
47  }
48 
52  public function ‪getQueryParamsAreEmptyByDefault()
53  {
54  self::assertEmpty($this->request->getQueryParams());
55  }
56 
61  {
62  $value = ['foo' => 'bar'];
63  ‪$request = $this->request->‪withQueryParams($value);
64  self::assertNotSame($this->request, ‪$request);
65  self::assertEquals($value, ‪$request->‪getQueryParams());
66  }
67 
71  public function ‪getCookieParamsAreEmptyByDefault()
72  {
73  self::assertEmpty($this->request->getCookieParams());
74  }
75 
80  {
81  $value = ['foo' => 'bar'];
82  ‪$request = $this->request->‪withCookieParams($value);
83  self::assertNotSame($this->request, ‪$request);
84  self::assertEquals($value, ‪$request->‪getCookieParams());
85  }
86 
90  public function ‪getUploadedFilesAreEmptyByDefault()
91  {
92  self::assertEmpty($this->request->getUploadedFiles());
93  }
94 
98  public function ‪getParsedBodyIsEmptyByDefault()
99  {
100  self::assertEmpty($this->request->getParsedBody());
101  }
102 
107  {
108  $value = ['foo' => 'bar'];
109  ‪$request = $this->request->‪withParsedBody($value);
110  self::assertNotSame($this->request, ‪$request);
111  self::assertEquals($value, ‪$request->‪getParsedBody());
112  }
113 
117  public function ‪getAttributesAreEmptyByDefault()
118  {
119  self::assertEmpty($this->request->getAttributes());
120  }
121 
126  {
127  ‪$request = $this->request->‪withAttribute('foo', 'bar');
128  self::assertNotSame($this->request, ‪$request);
129  self::assertEquals('bar', ‪$request->‪getAttribute('foo'));
130 
131  return ‪$request;
132  }
133 
138  {
140  $new = ‪$request->‪withoutAttribute('foo');
141  self::assertNotSame(‪$request, $new);
142  self::assertNull($new->getAttribute('foo', null));
143  }
144 
148  public function ‪constructorUsesProvidedArguments()
149  {
150  $server = [
151  'foo' => 'bar',
152  'baz' => 'bat',
153  ];
154 
155  $server['server'] = true;
156 
157  $files = [
158  'files' => new UploadedFile('php://temp', 0, 0),
159  ];
160 
161  $uri = new Uri('http://example.com');
162  $method = 'POST';
163  $headers = [
164  'host' => ['example.com'],
165  ];
166 
167  ‪$request = new ServerRequest(
168  $uri,
169  $method,
170  'php://memory',
171  $headers,
172  $server,
173  $files
174  );
175 
176  self::assertEquals($server, ‪$request->‪getServerParams());
177  self::assertEquals($files, ‪$request->‪getUploadedFiles());
178 
179  self::assertSame($uri, ‪$request->‪getUri());
180  self::assertEquals($method, ‪$request->‪getMethod());
181  self::assertEquals($headers, ‪$request->‪getHeaders());
182 
183  $body = ‪$request->‪getBody();
184  $r = new \ReflectionProperty($body, 'stream');
185  $r->setAccessible(true);
186  $stream = $r->getValue($body);
187  self::assertEquals('php://memory', $stream);
188  }
189 }
‪TYPO3\CMS\Core\Http\ServerRequest\getCookieParams
‪array getCookieParams()
Definition: ServerRequest.php:109
‪TYPO3\CMS\Core\Http\ServerRequest\withAttribute
‪static withAttribute($name, $value)
Definition: ServerRequest.php:328
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withQueryParamsMutatorReturnsCloneWithChanges
‪withQueryParamsMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:59
‪TYPO3\CMS\Core\Http\ServerRequest\withQueryParams
‪static withQueryParams(array $query)
Definition: ServerRequest.php:177
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\$request
‪ServerRequest $request
Definition: ServerRequestTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest
Definition: ServerRequestTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\setUp
‪setUp()
Definition: ServerRequestTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Http
Definition: ApplicationTypeTest.php:16
‪TYPO3\CMS\Core\Http\ServerRequest\getQueryParams
‪array getQueryParams()
Definition: ServerRequest.php:150
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\constructorUsesProvidedArguments
‪constructorUsesProvidedArguments()
Definition: ServerRequestTest.php:147
‪TYPO3\CMS\Core\Http\ServerRequest\withoutAttribute
‪static withoutAttribute($name)
Definition: ServerRequest.php:350
‪TYPO3\CMS\Core\Http\ServerRequest\getParsedBody
‪array object null getParsedBody()
Definition: ServerRequest.php:235
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withoutAttributeReturnsCloneWithoutAttribute
‪withoutAttributeReturnsCloneWithoutAttribute()
Definition: ServerRequestTest.php:136
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:29
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getQueryParamsAreEmptyByDefault
‪getQueryParamsAreEmptyByDefault()
Definition: ServerRequestTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withCookieParamsMutatorReturnsCloneWithChanges
‪withCookieParamsMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getParsedBodyIsEmptyByDefault
‪getParsedBodyIsEmptyByDefault()
Definition: ServerRequestTest.php:97
‪TYPO3\CMS\Core\Http\Request\getMethod
‪string getMethod()
Definition: Request.php:254
‪TYPO3\CMS\Core\Http\Message\getBody
‪Psr Http Message StreamInterface getBody()
Definition: Message.php:283
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Http\ServerRequest\withCookieParams
‪static withCookieParams(array $cookies)
Definition: ServerRequest.php:131
‪TYPO3\CMS\Core\Http\Request\getHeaders
‪array getHeaders()
Definition: Request.php:142
‪TYPO3\CMS\Core\Http\Request\getUri
‪Psr Http Message UriInterface getUri()
Definition: Request.php:290
‪TYPO3\CMS\Core\Http\ServerRequest\getUploadedFiles
‪array getUploadedFiles()
Definition: ServerRequest.php:196
‪TYPO3\CMS\Core\Http\ServerRequest\withParsedBody
‪static withParsedBody($data)
Definition: ServerRequest.php:268
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getAttributesAreEmptyByDefault
‪getAttributesAreEmptyByDefault()
Definition: ServerRequestTest.php:116
‪TYPO3\CMS\Core\Http\UploadedFile
Definition: UploadedFile.php:31
‪TYPO3\CMS\Core\Http\ServerRequest\getAttribute
‪mixed getAttribute($name, $default=null)
Definition: ServerRequest.php:307
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getServerParamsAreEmptyByDefault
‪getServerParamsAreEmptyByDefault()
Definition: ServerRequestTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getCookieParamsAreEmptyByDefault
‪getCookieParamsAreEmptyByDefault()
Definition: ServerRequestTest.php:70
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withAttributeMutatorReturnsCloneWithChanges
‪withAttributeMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:124
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getUploadedFilesAreEmptyByDefault
‪getUploadedFilesAreEmptyByDefault()
Definition: ServerRequestTest.php:89
‪TYPO3\CMS\Core\Http\ServerRequest\getServerParams
‪array getServerParams()
Definition: ServerRequest.php:94
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withParsedBodyMutatorReturnsCloneWithChanges
‪withParsedBodyMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:105