2015-03-16 11:28:23 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2024-05-10 15:09:14 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-03-16 11:28:23 +01:00
|
|
|
*/
|
|
|
|
|
2016-05-19 08:46:58 +02:00
|
|
|
namespace Test\Http\Client;
|
2015-03-16 11:28:23 +01:00
|
|
|
|
2018-02-08 13:39:27 +01:00
|
|
|
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
2021-10-21 12:37:51 +02:00
|
|
|
use GuzzleHttp\Psr7\Utils;
|
2016-05-19 08:46:58 +02:00
|
|
|
use OC\Http\Client\Response;
|
2015-03-16 11:28:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ResponseTest
|
|
|
|
*/
|
|
|
|
class ResponseTest extends \Test\TestCase {
|
|
|
|
/** @var GuzzleResponse */
|
|
|
|
private $guzzleResponse;
|
|
|
|
|
2019-11-27 15:27:18 +01:00
|
|
|
protected function setUp(): void {
|
2015-03-16 11:28:23 +01:00
|
|
|
parent::setUp();
|
2020-02-06 18:13:04 +01:00
|
|
|
$this->guzzleResponse = new GuzzleResponse(418);
|
2015-03-16 11:28:23 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 15:16:35 +01:00
|
|
|
public function testGetBody(): void {
|
2021-10-21 12:37:51 +02:00
|
|
|
$response = new Response($this->guzzleResponse->withBody(Utils::streamFor('MyResponse')));
|
2018-02-08 13:39:27 +01:00
|
|
|
$this->assertSame('MyResponse', $response->getBody());
|
2017-01-02 15:16:35 +01:00
|
|
|
}
|
|
|
|
|
2015-03-16 11:28:23 +01:00
|
|
|
public function testGetStatusCode(): void {
|
2018-02-08 13:39:27 +01:00
|
|
|
$response = new Response($this->guzzleResponse);
|
2020-02-06 18:13:04 +01:00
|
|
|
$this->assertSame(418, $response->getStatusCode());
|
2015-03-16 11:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHeader(): void {
|
2018-02-08 13:39:27 +01:00
|
|
|
$response = new Response($this->guzzleResponse->withHeader('bar', 'foo'));
|
|
|
|
$this->assertSame('foo', $response->getHeader('bar'));
|
2017-01-02 15:16:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHeaders(): void {
|
2018-02-08 13:39:27 +01:00
|
|
|
$response = new Response($this->guzzleResponse
|
|
|
|
->withHeader('bar', 'foo')
|
|
|
|
->withHeader('x-awesome', 'yes')
|
|
|
|
);
|
2017-01-02 15:16:35 +01:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'bar' => [
|
|
|
|
0 => 'foo',
|
|
|
|
],
|
|
|
|
'x-awesome' => [
|
|
|
|
0 => 'yes',
|
|
|
|
],
|
|
|
|
];
|
2018-02-08 13:39:27 +01:00
|
|
|
$this->assertSame($expected, $response->getHeaders());
|
|
|
|
$this->assertSame('yes', $response->getHeader('x-awesome'));
|
2015-03-16 11:28:23 +01:00
|
|
|
}
|
|
|
|
}
|