2017-08-15 16:45:23 +03:00
|
|
|
<?php
|
2018-09-01 23:00:00 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-08-15 16:45:23 +03:00
|
|
|
namespace GraphQL\Tests\Server;
|
|
|
|
|
|
|
|
use GraphQL\Executor\ExecutionResult;
|
|
|
|
use GraphQL\Server\Helper;
|
|
|
|
use GraphQL\Tests\Server\Psr7\PsrResponseStub;
|
2018-09-01 23:00:00 +03:00
|
|
|
use GraphQL\Tests\Server\Psr7\PsrStreamStub;
|
2018-07-29 18:43:10 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-09-01 23:00:00 +03:00
|
|
|
use function json_encode;
|
2017-08-15 16:45:23 +03:00
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class PsrResponseTest extends TestCase
|
2017-08-15 16:45:23 +03:00
|
|
|
{
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testConvertsResultToPsrResponse() : void
|
2017-08-15 16:45:23 +03:00
|
|
|
{
|
2018-09-01 23:00:00 +03:00
|
|
|
$result = new ExecutionResult(['key' => 'value']);
|
|
|
|
$stream = new PsrStreamStub();
|
2017-08-15 16:45:23 +03:00
|
|
|
$psrResponse = new PsrResponseStub();
|
|
|
|
|
|
|
|
$helper = new Helper();
|
|
|
|
|
|
|
|
/** @var PsrResponseStub $resp */
|
|
|
|
$resp = $helper->toPsrResponse($result, $psrResponse, $stream);
|
|
|
|
$this->assertSame(json_encode($result), $resp->body->content);
|
|
|
|
$this->assertSame(['Content-Type' => ['application/json']], $resp->headers);
|
|
|
|
}
|
|
|
|
}
|