2015-03-16 06:28:23 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com>
|
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
|
* later.
|
|
|
|
|
* See the COPYING-README file.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-05-19 02:46:58 -04:00
|
|
|
namespace Test\Http\Client;
|
2015-03-16 06:28:23 -04:00
|
|
|
|
2018-02-08 07:39:27 -05:00
|
|
|
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
2021-10-21 06:37:51 -04:00
|
|
|
use GuzzleHttp\Psr7\Utils;
|
2016-05-19 02:46:58 -04:00
|
|
|
use OC\Http\Client\Response;
|
2015-03-16 06:28:23 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ResponseTest
|
|
|
|
|
*/
|
|
|
|
|
class ResponseTest extends \Test\TestCase {
|
|
|
|
|
/** @var GuzzleResponse */
|
|
|
|
|
private $guzzleResponse;
|
|
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2015-03-16 06:28:23 -04:00
|
|
|
parent::setUp();
|
2020-02-06 12:13:04 -05:00
|
|
|
$this->guzzleResponse = new GuzzleResponse(418);
|
2015-03-16 06:28:23 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 09:16:35 -05:00
|
|
|
public function testGetBody() {
|
2021-10-21 06:37:51 -04:00
|
|
|
$response = new Response($this->guzzleResponse->withBody(Utils::streamFor('MyResponse')));
|
2018-02-08 07:39:27 -05:00
|
|
|
$this->assertSame('MyResponse', $response->getBody());
|
2017-01-02 09:16:35 -05:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 06:28:23 -04:00
|
|
|
public function testGetStatusCode() {
|
2018-02-08 07:39:27 -05:00
|
|
|
$response = new Response($this->guzzleResponse);
|
2020-02-06 12:13:04 -05:00
|
|
|
$this->assertSame(418, $response->getStatusCode());
|
2015-03-16 06:28:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetHeader() {
|
2018-02-08 07:39:27 -05:00
|
|
|
$response = new Response($this->guzzleResponse->withHeader('bar', 'foo'));
|
|
|
|
|
$this->assertSame('foo', $response->getHeader('bar'));
|
2017-01-02 09:16:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetHeaders() {
|
2018-02-08 07:39:27 -05:00
|
|
|
$response = new Response($this->guzzleResponse
|
|
|
|
|
->withHeader('bar', 'foo')
|
|
|
|
|
->withHeader('x-awesome', 'yes')
|
|
|
|
|
);
|
2017-01-02 09:16:35 -05:00
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
|
'bar' => [
|
|
|
|
|
0 => 'foo',
|
|
|
|
|
],
|
|
|
|
|
'x-awesome' => [
|
|
|
|
|
0 => 'yes',
|
|
|
|
|
],
|
|
|
|
|
];
|
2018-02-08 07:39:27 -05:00
|
|
|
$this->assertSame($expected, $response->getHeaders());
|
|
|
|
|
$this->assertSame('yes', $response->getHeader('x-awesome'));
|
2015-03-16 06:28:23 -04:00
|
|
|
}
|
|
|
|
|
}
|