nextcloud/tests/lib/Http/Client/ResponseTest.php

60 lines
1.4 KiB
PHP
Raw Normal View History

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
use GuzzleHttp\Psr7\Response as GuzzleResponse;
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;
protected function setUp(): void {
2015-03-16 13:28:23 +03:00
parent::setUp();
$this->guzzleResponse = new GuzzleResponse(418);
2015-03-16 13:28:23 +03:00
}
public function testGetBody() {
$response = new Response($this->guzzleResponse->withBody(stream_for('MyResponse')));
$this->assertSame('MyResponse', $response->getBody());
}
2015-03-16 13:28:23 +03:00
public function testGetStatusCode() {
$response = new Response($this->guzzleResponse);
$this->assertSame(418, $response->getStatusCode());
2015-03-16 13:28:23 +03:00
}
public function testGetHeader() {
$response = new Response($this->guzzleResponse->withHeader('bar', 'foo'));
$this->assertSame('foo', $response->getHeader('bar'));
}
public function testGetHeaders() {
$response = new Response($this->guzzleResponse
->withHeader('bar', 'foo')
->withHeader('x-awesome', 'yes')
);
$expected = [
'bar' => [
0 => 'foo',
],
'x-awesome' => [
0 => 'yes',
],
];
$this->assertSame($expected, $response->getHeaders());
$this->assertSame('yes', $response->getHeader('x-awesome'));
2015-03-16 13:28:23 +03:00
}
}