Do not use ServerRequestFactory::fromGlobals in tests

This commit is contained in:
Alejandro Celaya
2018-12-25 23:01:30 +01:00
parent 8b3324e143
commit 32070b1fa7
30 changed files with 126 additions and 140 deletions

View File

@@ -10,7 +10,7 @@ use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\ServerRequest;
class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
{
@@ -33,7 +33,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
$expectedResp = new Response();
$this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn($expectedResp);
$resp = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->requestHandler->reveal());
$resp = $this->middleware->process(new ServerRequest(), $this->requestHandler->reveal());
$this->assertSame($expectedResp, $resp);
}
@@ -45,7 +45,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
*/
public function properResponseIsReturned(?string $accept, array $query, string $expectedContentType)
{
$request = ServerRequestFactory::fromGlobals()->withQueryParams($query);
$request = (new ServerRequest())->withQueryParams($query);
if ($accept !== null) {
$request = $request->withHeader('Accept', $accept);
}
@@ -81,7 +81,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
*/
public function properBodyIsReturnedInPlainTextResponses(array $json, string $expectedBody)
{
$request = ServerRequestFactory::fromGlobals()->withQueryParams(['format' => 'txt']);
$request = (new ServerRequest())->withQueryParams(['format' => 'txt']);
$handle = $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(
new JsonResponse($json)