ResponseTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Http\Client;
  8. use GuzzleHttp\Psr7\Response as GuzzleResponse;
  9. use GuzzleHttp\Psr7\Utils;
  10. use OC\Http\Client\Response;
  11. /**
  12. * Class ResponseTest
  13. */
  14. class ResponseTest extends \Test\TestCase {
  15. /** @var GuzzleResponse */
  16. private $guzzleResponse;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->guzzleResponse = new GuzzleResponse(418);
  20. }
  21. public function testGetBody(): void {
  22. $response = new Response($this->guzzleResponse->withBody(Utils::streamFor('MyResponse')));
  23. $this->assertSame('MyResponse', $response->getBody());
  24. }
  25. public function testGetStatusCode(): void {
  26. $response = new Response($this->guzzleResponse);
  27. $this->assertSame(418, $response->getStatusCode());
  28. }
  29. public function testGetHeader(): void {
  30. $response = new Response($this->guzzleResponse->withHeader('bar', 'foo'));
  31. $this->assertSame('foo', $response->getHeader('bar'));
  32. }
  33. public function testGetHeaders(): void {
  34. $response = new Response($this->guzzleResponse
  35. ->withHeader('bar', 'foo')
  36. ->withHeader('x-awesome', 'yes')
  37. );
  38. $expected = [
  39. 'bar' => [
  40. 0 => 'foo',
  41. ],
  42. 'x-awesome' => [
  43. 0 => 'yes',
  44. ],
  45. ];
  46. $this->assertSame($expected, $response->getHeaders());
  47. $this->assertSame('yes', $response->getHeader('x-awesome'));
  48. }
  49. }