Update ServerRequestTest.php

This commit is contained in:
李铭昕 2019-08-30 14:02:24 +08:00
parent 25e3f3c96b
commit a1548ff30d

View File

@ -44,14 +44,20 @@ class ServerRequestTest extends TestCase
$request->shouldReceive('getBody')->andReturn(new SwooleStream(json_encode($json)));
$this->assertSame($json, RequestStub::normalizeParsedBody($data, $request));
$request = Mockery::mock(RequestInterface::class);
$request->shouldReceive('getHeaderLine')->with('Content-Type')->andReturn('application/JSON');
$request->shouldReceive('getBody')->andReturn(new SwooleStream(json_encode($json)));
$this->assertSame($json, RequestStub::normalizeParsedBody($data, $request));
$request = Mockery::mock(RequestInterface::class);
$request->shouldReceive('getHeaderLine')->with('Content-Type')->andReturn('application/json; charset=utf-8');
$request->shouldReceive('getBody')->andReturn(new SwooleStream('xxxx'));
$this->assertSame([], RequestStub::normalizeParsedBody($data, $request));
}
public function testNormalizeParsedBodyInvalidContentType()
{
$data = ['id' => 1];
$json = ['name' => 'Hyperf'];
$request = Mockery::mock(RequestInterface::class);
$request->shouldReceive('getHeaderLine')->with('Content-Type')->andReturn('application/JSON');
$request->shouldReceive('getBody')->andReturn(new SwooleStream(json_encode($json)));
$this->assertSame($json, RequestStub::normalizeParsedBody($data, $request));
}
}