2015-03-16 13:28:23 +03: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 09:46:58 +03:00
|
|
|
namespace Test\Http\Client;
|
2015-03-16 13:28:23 +03:00
|
|
|
|
2018-02-08 15:39:27 +03:00
|
|
|
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
2019-11-22 22:52:10 +03:00
|
|
|
use function GuzzleHttp\Psr7\stream_for;
|
2016-05-19 09:46:58 +03:00
|
|
|
use OC\Http\Client\Response;
|
2015-03-16 13:28:23 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ResponseTest
|
|
|
|
*/
|
|
|
|
class ResponseTest extends \Test\TestCase {
|
|
|
|
/** @var GuzzleResponse */
|
|
|
|
private $guzzleResponse;
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->guzzleResponse = new GuzzleResponse(1337);
|
|
|
|
}
|
|
|
|
|
2017-01-02 17:16:35 +03:00
|
|
|
public function testGetBody() {
|
2018-02-08 15:39:27 +03:00
|
|
|
$response = new Response($this->guzzleResponse->withBody(stream_for('MyResponse')));
|
|
|
|
$this->assertSame('MyResponse', $response->getBody());
|
2017-01-02 17:16:35 +03:00
|
|
|
}
|
|
|
|
|
2015-03-16 13:28:23 +03:00
|
|
|
public function testGetStatusCode() {
|
2018-02-08 15:39:27 +03:00
|
|
|
$response = new Response($this->guzzleResponse);
|
|
|
|
$this->assertSame(1337, $response->getStatusCode());
|
2015-03-16 13:28:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHeader() {
|
2018-02-08 15:39:27 +03:00
|
|
|
$response = new Response($this->guzzleResponse->withHeader('bar', 'foo'));
|
|
|
|
$this->assertSame('foo', $response->getHeader('bar'));
|
2017-01-02 17:16:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHeaders() {
|
2018-02-08 15:39:27 +03:00
|
|
|
$response = new Response($this->guzzleResponse
|
|
|
|
->withHeader('bar', 'foo')
|
|
|
|
->withHeader('x-awesome', 'yes')
|
|
|
|
);
|
2017-01-02 17:16:35 +03:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'bar' => [
|
|
|
|
0 => 'foo',
|
|
|
|
],
|
|
|
|
'x-awesome' => [
|
|
|
|
0 => 'yes',
|
|
|
|
],
|
|
|
|
];
|
2018-02-08 15:39:27 +03:00
|
|
|
$this->assertSame($expected, $response->getHeaders());
|
|
|
|
$this->assertSame('yes', $response->getHeader('x-awesome'));
|
2015-03-16 13:28:23 +03:00
|
|
|
}
|
|
|
|
}
|