public function testGetJsonParsedBodyWithCharsetHeader() { $body = Mockery::mock(StreamInterface::class); $body->shouldReceive('__toString')->andReturn('{"hello":[1,2,3,4,5]}'); $serverRequest = $this->factory->create(['HTTP_CONTENT_TYPE' => 'application/json;charset=UTF-8'], [], [], [], [], $body); static::assertEquals(['hello' => [1, 2, 3, 4, 5]], $serverRequest->getParsedBody()); }
/** * @dataProvider provideMethodAndBody */ public function testRequestPost($method, $contentType) { $servers = ['HTTP_CONTENT_TYPE' => $contentType['type'], 'REQUEST_METHOD' => $method]; $body = Mockery::mock(StreamInterface::class); $body->shouldReceive('__toString')->andReturn($contentType['input']); $factory = new ServerRequestFactory(new UploadedFileFactory()); // if method === post => php can parsed body! $posts = $method === 'POST' && $contentType['type'] !== 'application/json' ? $contentType['expected'] : []; $request = $factory->create($servers, [], $posts, [], [], $body); $this->assertEquals($contentType['expected'], $request->getParsedBody()); }