. */ namespace SP\Tests; use Goutte\Client; use JsonException; use PHPUnit\Framework\TestCase; use stdClass; use Symfony\Component\BrowserKit\Response; /** * Class WebTestCase */ abstract class WebTestCase extends TestCase { /** * @throws JsonException */ protected static function postJson(string $url, $content = ''): Client { $client = self::createClient(); $client->request( 'POST', $url, [], [], ['HTTP_CONTENT_TYPE' => 'application/json'], json_encode($content, JSON_THROW_ON_ERROR) ); return $client; } protected static function createClient(array $server = []): Client { return new Client($server); } protected static function checkAndProcessJsonResponse( Client $client, int $httpCode = 200 ): stdClass { /** @var Response $response */ $response = $client->getResponse(); self::assertEquals($httpCode, $response->getStatus()); self::assertEquals('application/json; charset=utf-8', $response->getHeader('Content-Type')); return json_decode( $response->getContent(), false, 512, JSON_THROW_ON_ERROR ); } }