1
0

ResponseTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Http\Client;
  9. use GuzzleHttp\Psr7\Response as GuzzleResponse;
  10. use function GuzzleHttp\Psr7\stream_for;
  11. use OC\Http\Client\Response;
  12. /**
  13. * Class ResponseTest
  14. */
  15. class ResponseTest extends \Test\TestCase {
  16. /** @var GuzzleResponse */
  17. private $guzzleResponse;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->guzzleResponse = new GuzzleResponse(418);
  21. }
  22. public function testGetBody() {
  23. $response = new Response($this->guzzleResponse->withBody(stream_for('MyResponse')));
  24. $this->assertSame('MyResponse', $response->getBody());
  25. }
  26. public function testGetStatusCode() {
  27. $response = new Response($this->guzzleResponse);
  28. $this->assertSame(418, $response->getStatusCode());
  29. }
  30. public function testGetHeader() {
  31. $response = new Response($this->guzzleResponse->withHeader('bar', 'foo'));
  32. $this->assertSame('foo', $response->getHeader('bar'));
  33. }
  34. public function testGetHeaders() {
  35. $response = new Response($this->guzzleResponse
  36. ->withHeader('bar', 'foo')
  37. ->withHeader('x-awesome', 'yes')
  38. );
  39. $expected = [
  40. 'bar' => [
  41. 0 => 'foo',
  42. ],
  43. 'x-awesome' => [
  44. 0 => 'yes',
  45. ],
  46. ];
  47. $this->assertSame($expected, $response->getHeaders());
  48. $this->assertSame('yes', $response->getHeader('x-awesome'));
  49. }
  50. }