diff options
Diffstat (limited to 'tests/PHPUnit/TestCases/HttpResponseTestCase.php')
| -rw-r--r-- | tests/PHPUnit/TestCases/HttpResponseTestCase.php | 37 | 
1 files changed, 37 insertions, 0 deletions
| diff --git a/tests/PHPUnit/TestCases/HttpResponseTestCase.php b/tests/PHPUnit/TestCases/HttpResponseTestCase.php new file mode 100644 index 0000000..855e594 --- /dev/null +++ b/tests/PHPUnit/TestCases/HttpResponseTestCase.php @@ -0,0 +1,37 @@ +<?php + +namespace Tests\PHPUnit\TestCases; + +use GuzzleHttp\Client; +use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\TestCase; + +class HttpResponseTestCase extends TestCase +{ +  protected Client $client; +   +  protected function setUp(): void +  { +    $this->client = new Client([ +      "base_uri" => "http://localhost:8080", +    ]); +  } +   +  /** +   * @param array $options +   */ +  public function request(string $method, string $path, array $options = []): Response +  { +    return $this->client->request( +      $method, +      $path, +      ["http_errors" => false] + $options +    ); +  } +   +  public function hasJsonBody(Response $response): bool +  { +    json_decode((string)$response->getBody()); +    return json_last_error() === JSON_ERROR_NONE; +  } +} | 
