‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
27 class ‪ServerRequestTest extends UnitTestCase
28 {
32  protected ‪$request;
33 
34  protected function ‪setUp()
35  {
36  $this->request = new ‪ServerRequest();
37  }
38 
42  public function ‪getServerParamsAreEmptyByDefault()
43  {
44  $this->assertEmpty($this->request->getServerParams());
45  }
46 
50  public function ‪getQueryParamsAreEmptyByDefault()
51  {
52  $this->assertEmpty($this->request->getQueryParams());
53  }
54 
59  {
60  $value = ['foo' => 'bar'];
61  ‪$request = $this->request->‪withQueryParams($value);
62  $this->assertNotSame($this->request, ‪$request);
63  $this->assertEquals($value, ‪$request->‪getQueryParams());
64  }
65 
69  public function ‪getCookieParamsAreEmptyByDefault()
70  {
71  $this->assertEmpty($this->request->getCookieParams());
72  }
73 
78  {
79  $value = ['foo' => 'bar'];
80  ‪$request = $this->request->‪withCookieParams($value);
81  $this->assertNotSame($this->request, ‪$request);
82  $this->assertEquals($value, ‪$request->‪getCookieParams());
83  }
84 
88  public function ‪getUploadedFilesAreEmptyByDefault()
89  {
90  $this->assertEmpty($this->request->getUploadedFiles());
91  }
92 
96  public function ‪getParsedBodyIsEmptyByDefault()
97  {
98  $this->assertEmpty($this->request->getParsedBody());
99  }
100 
105  {
106  $value = ['foo' => 'bar'];
107  ‪$request = $this->request->‪withParsedBody($value);
108  $this->assertNotSame($this->request, ‪$request);
109  $this->assertEquals($value, ‪$request->‪getParsedBody());
110  }
111 
115  public function ‪getAttributesAreEmptyByDefault()
116  {
117  $this->assertEmpty($this->request->getAttributes());
118  }
119 
124  {
125  ‪$request = $this->request->‪withAttribute('foo', 'bar');
126  $this->assertNotSame($this->request, ‪$request);
127  $this->assertEquals('bar', ‪$request->‪getAttribute('foo'));
128 
129  return ‪$request;
130  }
131 
136  {
138  $new = ‪$request->‪withoutAttribute('foo');
139  $this->assertNotSame(‪$request, $new);
140  $this->assertNull($new->getAttribute('foo', null));
141  }
142 
146  public function ‪constructorUsesProvidedArguments()
147  {
148  $server = [
149  'foo' => 'bar',
150  'baz' => 'bat',
151  ];
152 
153  $server['server'] = true;
154 
155  $files = [
156  'files' => new UploadedFile('php://temp', 0, 0),
157  ];
158 
159  $uri = new Uri('http://example.com');
160  $method = 'POST';
161  $headers = [
162  'host' => ['example.com'],
163  ];
164 
165  ‪$request = new ServerRequest(
166  $uri,
167  $method,
168  'php://memory',
169  $headers,
170  $server,
171  $files
172  );
173 
174  $this->assertEquals($server, ‪$request->‪getServerParams());
175  $this->assertEquals($files, ‪$request->‪getUploadedFiles());
176 
177  $this->assertSame($uri, ‪$request->‪getUri());
178  $this->assertEquals($method, ‪$request->‪getMethod());
179  $this->assertEquals($headers, ‪$request->‪getHeaders());
180 
181  $body = ‪$request->‪getBody();
182  $r = new \ReflectionProperty($body, 'stream');
183  $r->setAccessible(true);
184  $stream = $r->getValue($body);
185  $this->assertEquals('php://memory', $stream);
186  }
187 }
‪TYPO3\CMS\Core\Http\ServerRequest\getCookieParams
‪array getCookieParams()
Definition: ServerRequest.php:107
‪TYPO3\CMS\Core\Http\ServerRequest\withAttribute
‪static withAttribute($name, $value)
Definition: ServerRequest.php:326
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withQueryParamsMutatorReturnsCloneWithChanges
‪withQueryParamsMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:57
‪TYPO3\CMS\Core\Http\ServerRequest\withQueryParams
‪static withQueryParams(array $query)
Definition: ServerRequest.php:175
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\$request
‪ServerRequest $request
Definition: ServerRequestTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest
Definition: ServerRequestTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\setUp
‪setUp()
Definition: ServerRequestTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Http
‪TYPO3\CMS\Core\Http\ServerRequest\getQueryParams
‪array getQueryParams()
Definition: ServerRequest.php:148
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\constructorUsesProvidedArguments
‪constructorUsesProvidedArguments()
Definition: ServerRequestTest.php:145
‪TYPO3\CMS\Core\Http\ServerRequest\withoutAttribute
‪static withoutAttribute($name)
Definition: ServerRequest.php:348
‪TYPO3\CMS\Core\Http\ServerRequest\getParsedBody
‪array object null getParsedBody()
Definition: ServerRequest.php:233
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withoutAttributeReturnsCloneWithoutAttribute
‪withoutAttributeReturnsCloneWithoutAttribute()
Definition: ServerRequestTest.php:134
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:27
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getQueryParamsAreEmptyByDefault
‪getQueryParamsAreEmptyByDefault()
Definition: ServerRequestTest.php:49
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withCookieParamsMutatorReturnsCloneWithChanges
‪withCookieParamsMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:76
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getParsedBodyIsEmptyByDefault
‪getParsedBodyIsEmptyByDefault()
Definition: ServerRequestTest.php:95
‪TYPO3\CMS\Core\Http\Request\getMethod
‪string getMethod()
Definition: Request.php:253
‪TYPO3\CMS\Core\Http\Message\getBody
‪Psr Http Message StreamInterface getBody()
Definition: Message.php:282
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:35
‪TYPO3\CMS\Core\Http\ServerRequest\withCookieParams
‪static withCookieParams(array $cookies)
Definition: ServerRequest.php:129
‪TYPO3\CMS\Core\Http\Request\getHeaders
‪array getHeaders()
Definition: Request.php:141
‪TYPO3\CMS\Core\Http\Request\getUri
‪Psr Http Message UriInterface getUri()
Definition: Request.php:289
‪TYPO3\CMS\Core\Http\ServerRequest\getUploadedFiles
‪array getUploadedFiles()
Definition: ServerRequest.php:194
‪TYPO3\CMS\Core\Http\ServerRequest\withParsedBody
‪static withParsedBody($data)
Definition: ServerRequest.php:266
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getAttributesAreEmptyByDefault
‪getAttributesAreEmptyByDefault()
Definition: ServerRequestTest.php:114
‪TYPO3\CMS\Core\Http\UploadedFile
Definition: UploadedFile.php:31
‪TYPO3\CMS\Core\Http\ServerRequest\getAttribute
‪mixed getAttribute($name, $default=null)
Definition: ServerRequest.php:305
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getServerParamsAreEmptyByDefault
‪getServerParamsAreEmptyByDefault()
Definition: ServerRequestTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getCookieParamsAreEmptyByDefault
‪getCookieParamsAreEmptyByDefault()
Definition: ServerRequestTest.php:68
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withAttributeMutatorReturnsCloneWithChanges
‪withAttributeMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:122
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\getUploadedFilesAreEmptyByDefault
‪getUploadedFilesAreEmptyByDefault()
Definition: ServerRequestTest.php:87
‪TYPO3\CMS\Core\Http\ServerRequest\getServerParams
‪array getServerParams()
Definition: ServerRequest.php:92
‪TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withParsedBodyMutatorReturnsCloneWithChanges
‪withParsedBodyMutatorReturnsCloneWithChanges()
Definition: ServerRequestTest.php:103