Exemple #1
0
 public function testNewInstanceWhenNewParsedBody()
 {
     $parsedBody = ['testK' => 'testV'];
     $serverRequest = $this->serverRequest->withParsedBody($parsedBody);
     $this->assertNotSame($this->serverRequest, $serverRequest);
     $this->assertEquals($parsedBody, $serverRequest->getParsedBody());
 }
Exemple #2
0
 /**
  * @param  array  $data
  * @return ServerRequest
  */
 public function getRequest(array $data = [])
 {
     $method = $this->getMethod();
     $uri = new Uri($this->getAction());
     $body = null;
     if ($this->isGet()) {
         foreach ($this->getData($data) as $key => $value) {
             $uri = Uri::withQueryValue($uri, $key, $value);
         }
     } elseif ($this->isMultipart()) {
         $body = new MultipartStream($this->getMultipartData($data), $this->getMultipartBoundary());
     } else {
         $body = http_build_query($this->getData($data), null, '&');
     }
     $request = new ServerRequest($method, $uri, $this->getHeaders(), $body);
     $files = $this->getFiles();
     return $request->withParsedBody(self::toNestedParams($this->getData($data)))->withAttribute('FILES', $files)->withUploadedFiles(ServerRequest::normalizeFiles($files));
 }
 public function testParsedBody()
 {
     $request1 = new ServerRequest('GET', '/');
     $params = ['name' => 'value'];
     $request2 = $request1->withParsedBody($params);
     $this->assertNotSame($request2, $request1);
     $this->assertEmpty($request1->getParsedBody());
     $this->assertSame($params, $request2->getParsedBody());
 }