diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-02-14 22:26:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-14 22:26:19 +0100 |
commit | 24f96513fde993268c1286ded393252020d4f9ae (patch) | |
tree | 4da55bdec980bc7ecf6452fce1e4d3515f5be9eb /tests | |
parent | 236086c457672742eb3ff57acf66587549b69345 (diff) | |
parent | a815185bb4960312b6e15cda236db09d8ca72c01 (diff) | |
download | nextcloud-server-24f96513fde993268c1286ded393252020d4f9ae.tar.gz nextcloud-server-24f96513fde993268c1286ded393252020d4f9ae.zip |
Merge pull request #8259 from nextcloud/guzzle6
update guzzlehttp/guzzle to 6.3.0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/CheckSetupControllerTest.php | 5 | ||||
-rw-r--r-- | tests/lib/Http/Client/ClientServiceTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Http/Client/ClientTest.php | 49 | ||||
-rw-r--r-- | tests/lib/Http/Client/ResponseTest.php | 28 |
4 files changed, 37 insertions, 48 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index 3f47819bcbd..a0ee7f6cae6 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -21,6 +21,7 @@ namespace Tests\Settings\Controller; +use Guzzle\Http\Message\Response; use OC\Settings\Controller\CheckSetupController; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDisplayResponse; @@ -460,7 +461,7 @@ class CheckSetupControllerTest extends TestCase { ->disableOriginalConstructor()->getMock(); $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException') ->disableOriginalConstructor()->getMock(); - $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface') + $response = $this->getMockBuilder(Response::class) ->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('getStatusCode') @@ -494,7 +495,7 @@ class CheckSetupControllerTest extends TestCase { ->disableOriginalConstructor()->getMock(); $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException') ->disableOriginalConstructor()->getMock(); - $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface') + $response = $this->getMockBuilder(Response::class) ->disableOriginalConstructor()->getMock(); $response->expects($this->once()) ->method('getStatusCode') diff --git a/tests/lib/Http/Client/ClientServiceTest.php b/tests/lib/Http/Client/ClientServiceTest.php index 48330dc33c0..1bfaf050355 100644 --- a/tests/lib/Http/Client/ClientServiceTest.php +++ b/tests/lib/Http/Client/ClientServiceTest.php @@ -9,6 +9,7 @@ namespace Test\Http\Client; use GuzzleHttp\Client as GuzzleClient; +use GuzzleHttp\HandlerStack; use OC\Http\Client\Client; use OC\Http\Client\ClientService; use OCP\ICertificateManager; @@ -22,7 +23,7 @@ class ClientServiceTest extends \Test\TestCase { $config = $this->createMock(IConfig::class); $certificateManager = $this->createMock(ICertificateManager::class); - $expected = new Client($config, $certificateManager, new GuzzleClient()); + $expected = new Client($config, $certificateManager, new GuzzleClient(), HandlerStack::create()); $clientService = new ClientService($config, $certificateManager); $this->assertEquals($expected, $clientService->newClient()); } diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php index 1b0a51b7395..ec4ca6ec90c 100644 --- a/tests/lib/Http/Client/ClientTest.php +++ b/tests/lib/Http/Client/ClientTest.php @@ -8,7 +8,8 @@ namespace Test\Http\Client; -use GuzzleHttp\Message\Response; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Psr7\Response; use OC\Http\Client\Client; use OC\Security\CertificateManager; use OCP\ICertificateManager; @@ -37,7 +38,8 @@ class ClientTest extends \Test\TestCase { $this->client = new Client( $this->config, $this->certificateManager, - $this->guzzleClient + $this->guzzleClient, + HandlerStack::create() ); } @@ -84,37 +86,37 @@ class ClientTest extends \Test\TestCase { } public function testGet() { - $this->guzzleClient->method('get') + $this->guzzleClient->method('request') ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->get('http://localhost/', [])->getStatusCode()); } public function testPost() { - $this->guzzleClient->method('post') + $this->guzzleClient->method('request') ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->post('http://localhost/', [])->getStatusCode()); } public function testPut() { - $this->guzzleClient->method('put') + $this->guzzleClient->method('request') ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->put('http://localhost/', [])->getStatusCode()); } public function testDelete() { - $this->guzzleClient->method('delete') + $this->guzzleClient->method('request') ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->delete('http://localhost/', [])->getStatusCode()); } public function testOptions() { - $this->guzzleClient->method('options') + $this->guzzleClient->method('request') ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode()); } public function testHead() { - $this->guzzleClient->method('head') + $this->guzzleClient->method('request') ->willReturn(new Response(1337)); $this->assertEquals(1337, $this->client->head('http://localhost/', [])->getStatusCode()); } @@ -129,16 +131,10 @@ class ClientTest extends \Test\TestCase { ->expects($this->once()) ->method('listCertificates') ->willReturn([]); - $this->guzzleClient - ->expects($this->at(0)) - ->method('setDefaultOption') - ->with('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); - $this->guzzleClient - ->expects($this->at(1)) - ->method('setDefaultOption') - ->with('headers/User-Agent', 'Nextcloud Server Crawler'); - self::invokePrivate($this->client, 'setDefaultOptions'); + $this->assertEquals([ + 'verify' => \OC::$SERVERROOT . '/resources/config/ca-bundle.crt' + ], self::invokePrivate($this->client, 'getRequestOptions')); } public function testSetDefaultOptionsWithProxy() { @@ -157,19 +153,10 @@ class ClientTest extends \Test\TestCase { ->method('getAbsoluteBundlePath') ->with(null) ->willReturn('/my/path.crt'); - $this->guzzleClient - ->expects($this->at(0)) - ->method('setDefaultOption') - ->with('verify', '/my/path.crt'); - $this->guzzleClient - ->expects($this->at(1)) - ->method('setDefaultOption') - ->with('headers/User-Agent', 'Nextcloud Server Crawler'); - $this->guzzleClient - ->expects($this->at(2)) - ->method('setDefaultOption') - ->with('proxy', 'foo'); - - self::invokePrivate($this->client, 'setDefaultOptions'); + + $this->assertEquals([ + 'verify' => '/my/path.crt', + 'proxy' => 'foo' + ], self::invokePrivate($this->client, 'getRequestOptions')); } } diff --git a/tests/lib/Http/Client/ResponseTest.php b/tests/lib/Http/Client/ResponseTest.php index 2e5a47b7f4a..d50f9a717d5 100644 --- a/tests/lib/Http/Client/ResponseTest.php +++ b/tests/lib/Http/Client/ResponseTest.php @@ -8,42 +8,42 @@ namespace Test\Http\Client; -use GuzzleHttp\Stream\Stream; -use GuzzleHttp\Message\Response as GuzzleResponse; +use function GuzzleHttp\Psr7\stream_for; +use GuzzleHttp\Psr7\Response as GuzzleResponse; use OC\Http\Client\Response; /** * Class ResponseTest */ class ResponseTest extends \Test\TestCase { - /** @var Response */ - private $response; /** @var GuzzleResponse */ private $guzzleResponse; public function setUp() { parent::setUp(); $this->guzzleResponse = new GuzzleResponse(1337); - $this->response = new Response($this->guzzleResponse); } public function testGetBody() { - $this->guzzleResponse->setBody(Stream::factory('MyResponse')); - $this->assertSame('MyResponse', $this->response->getBody()); + $response = new Response($this->guzzleResponse->withBody(stream_for('MyResponse'))); + $this->assertSame('MyResponse', $response->getBody()); } public function testGetStatusCode() { - $this->assertSame(1337, $this->response->getStatusCode()); + $response = new Response($this->guzzleResponse); + $this->assertSame(1337, $response->getStatusCode()); } public function testGetHeader() { - $this->guzzleResponse->setHeader('bar', 'foo'); - $this->assertSame('foo', $this->response->getHeader('bar')); + $response = new Response($this->guzzleResponse->withHeader('bar', 'foo')); + $this->assertSame('foo', $response->getHeader('bar')); } public function testGetHeaders() { - $this->guzzleResponse->setHeader('bar', 'foo'); - $this->guzzleResponse->setHeader('x-awesome', 'yes'); + $response = new Response($this->guzzleResponse + ->withHeader('bar', 'foo') + ->withHeader('x-awesome', 'yes') + ); $expected = [ 'bar' => [ @@ -53,7 +53,7 @@ class ResponseTest extends \Test\TestCase { 0 => 'yes', ], ]; - $this->assertSame($expected, $this->response->getHeaders()); - $this->assertSame('yes', $this->response->getHeader('x-awesome')); + $this->assertSame($expected, $response->getHeaders()); + $this->assertSame('yes', $response->getHeader('x-awesome')); } } |