diff --git a/.drone.yml b/.drone.yml
index de49cbbdbc4a..5c5d29c66b0e 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -182,6 +182,7 @@ pipeline:
- cd /drone/src/apps
- git clone https://github.com/owncloud/files_primary_s3.git
- cd files_primary_s3
+ - git checkout update-guzzle-6
- composer install
- cp tests/drone/${OBJECTSTORE}.config.php /drone/src/config
- cd /drone/src
diff --git a/composer.json b/composer.json
index 6c6a93f086de..f621e1bf47cf 100644
--- a/composer.json
+++ b/composer.json
@@ -49,7 +49,7 @@
"nikic/php-parser": "^4.0",
"icewind/streams": "0.7.1",
"swiftmailer/swiftmailer": "^6.0",
- "guzzlehttp/guzzle": "^5.3",
+ "guzzlehttp/guzzle": "^6.3",
"league/flysystem": "^1.0",
"pear/pear-core-minimal": "^v1.10",
"interfasys/lognormalizer": "^v1.0",
diff --git a/composer.lock b/composer.lock
index 4742fab81da5..b09282385fff 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "4dad05f538f9cf922397f36db89e10e4",
+ "content-hash": "851945ca27076575dbc2e70c879b4fb5",
"packages": [
{
"name": "bantu/ini-get-wrapper",
@@ -834,29 +834,41 @@
},
{
"name": "guzzlehttp/guzzle",
- "version": "5.3.3",
+ "version": "6.3.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
- "reference": "93bbdb30d59be6cd9839495306c65f2907370eb9"
+ "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle/zipball/93bbdb30d59be6cd9839495306c65f2907370eb9",
- "reference": "93bbdb30d59be6cd9839495306c65f2907370eb9",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
+ "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"shasum": ""
},
"require": {
- "guzzlehttp/ringphp": "^1.1",
- "php": ">=5.4.0",
- "react/promise": "^2.2"
+ "guzzlehttp/promises": "^1.0",
+ "guzzlehttp/psr7": "^1.4",
+ "php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
- "phpunit/phpunit": "^4.0"
+ "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
+ "psr/log": "^1.0"
+ },
+ "suggest": {
+ "psr/log": "Required for using the Log middleware"
},
"type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.3-dev"
+ }
+ },
"autoload": {
+ "files": [
+ "src/functions_include.php"
+ ],
"psr-4": {
"GuzzleHttp\\": "src/"
}
@@ -872,7 +884,7 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients",
+ "description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
@@ -883,44 +895,41 @@
"rest",
"web service"
],
- "time": "2018-07-31T13:33:10+00:00"
+ "time": "2018-04-22T15:46:56+00:00"
},
{
- "name": "guzzlehttp/ringphp",
- "version": "1.1.1",
+ "name": "guzzlehttp/promises",
+ "version": "v1.3.1",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/RingPHP.git",
- "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b"
+ "url": "https://github.com/guzzle/promises.git",
+ "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/5e2a174052995663dd68e6b5ad838afd47dd615b",
- "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
+ "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
- "guzzlehttp/streams": "~3.0",
- "php": ">=5.4.0",
- "react/promise": "~2.0"
+ "php": ">=5.5.0"
},
"require-dev": {
- "ext-curl": "*",
- "phpunit/phpunit": "~4.0"
- },
- "suggest": {
- "ext-curl": "Guzzle will use specific adapters if cURL is present"
+ "phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.1-dev"
+ "dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
- "GuzzleHttp\\Ring\\": "src/"
- }
+ "GuzzleHttp\\Promise\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -933,39 +942,54 @@
"homepage": "https://github.com/mtdowling"
}
],
- "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.",
- "time": "2018-07-31T13:22:33+00:00"
+ "description": "Guzzle promises library",
+ "keywords": [
+ "promise"
+ ],
+ "time": "2016-12-20T10:07:11+00:00"
},
{
- "name": "guzzlehttp/streams",
- "version": "3.0.0",
+ "name": "guzzlehttp/psr7",
+ "version": "1.6.1",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/streams.git",
- "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5"
+ "url": "https://github.com/guzzle/psr7.git",
+ "reference": "239400de7a173fe9901b9ac7c06497751f00727a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
- "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a",
+ "reference": "239400de7a173fe9901b9ac7c06497751f00727a",
"shasum": ""
},
"require": {
- "php": ">=5.4.0"
+ "php": ">=5.4.0",
+ "psr/http-message": "~1.0",
+ "ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
+ },
+ "provide": {
+ "psr/http-message-implementation": "1.0"
},
"require-dev": {
- "phpunit/phpunit": "~4.0"
+ "ext-zlib": "*",
+ "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8"
+ },
+ "suggest": {
+ "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0-dev"
+ "dev-master": "1.6-dev"
}
},
"autoload": {
"psr-4": {
- "GuzzleHttp\\Stream\\": "src/"
- }
+ "GuzzleHttp\\Psr7\\": "src/"
+ },
+ "files": [
+ "src/functions_include.php"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -976,15 +1000,24 @@
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
+ },
+ {
+ "name": "Tobias Schultze",
+ "homepage": "https://github.com/Tobion"
}
],
- "description": "Provides a simple abstraction over streams of data",
- "homepage": "http://guzzlephp.org/",
+ "description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
- "Guzzle",
- "stream"
+ "http",
+ "message",
+ "psr-7",
+ "request",
+ "response",
+ "stream",
+ "uri",
+ "url"
],
- "time": "2014-10-12T19:18:40+00:00"
+ "time": "2019-07-01T23:21:34+00:00"
},
{
"name": "icewind/streams",
@@ -1817,6 +1850,56 @@
],
"time": "2017-02-14T16:28:37+00:00"
},
+ {
+ "name": "psr/http-message",
+ "version": "1.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/http-message.git",
+ "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
+ "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psr\\Http\\Message\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
+ }
+ ],
+ "description": "Common interface for HTTP messages",
+ "homepage": "https://github.com/php-fig/http-message",
+ "keywords": [
+ "http",
+ "http-message",
+ "psr",
+ "psr-7",
+ "request",
+ "response"
+ ],
+ "time": "2016-08-06T14:39:51+00:00"
+ },
{
"name": "psr/log",
"version": "1.1.0",
@@ -1996,32 +2079,30 @@
"time": "2014-02-06T20:53:21+00:00"
},
{
- "name": "react/promise",
- "version": "v2.7.1",
+ "name": "ralouphie/getallheaders",
+ "version": "3.0.3",
"source": {
"type": "git",
- "url": "https://github.com/reactphp/promise.git",
- "reference": "31ffa96f8d2ed0341a57848cbb84d88b89dd664d"
+ "url": "https://github.com/ralouphie/getallheaders.git",
+ "reference": "120b605dfeb996808c31b6477290a714d356e822"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/reactphp/promise/zipball/31ffa96f8d2ed0341a57848cbb84d88b89dd664d",
- "reference": "31ffa96f8d2ed0341a57848cbb84d88b89dd664d",
+ "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
+ "reference": "120b605dfeb996808c31b6477290a714d356e822",
"shasum": ""
},
"require": {
- "php": ">=5.4.0"
+ "php": ">=5.6"
},
"require-dev": {
- "phpunit/phpunit": "~4.8"
+ "php-coveralls/php-coveralls": "^2.1",
+ "phpunit/phpunit": "^5 || ^6.5"
},
"type": "library",
"autoload": {
- "psr-4": {
- "React\\Promise\\": "src/"
- },
"files": [
- "src/functions_include.php"
+ "src/getallheaders.php"
]
},
"notification-url": "https://packagist.org/downloads/",
@@ -2030,16 +2111,12 @@
],
"authors": [
{
- "name": "Jan Sorgalla",
- "email": "jsorgalla@gmail.com"
+ "name": "Ralph Khattar",
+ "email": "ralph.khattar@gmail.com"
}
],
- "description": "A lightweight implementation of CommonJS Promises/A for PHP",
- "keywords": [
- "promise",
- "promises"
- ],
- "time": "2019-01-07T21:25:54+00:00"
+ "description": "A polyfill for getallheaders.",
+ "time": "2019-03-08T08:55:37+00:00"
},
{
"name": "sabre/dav",
diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php
index af43b15c023d..f045a1b9ec9f 100644
--- a/lib/private/Files/Storage/DAV.php
+++ b/lib/private/Files/Storage/DAV.php
@@ -34,7 +34,6 @@
use Exception;
use GuzzleHttp\Exception\RequestException;
-use GuzzleHttp\Message\ResponseInterface;
use OC\Files\Filesystem;
use OC\Files\Stream\Close;
use Icewind\Streams\IteratorDirectory;
@@ -50,6 +49,7 @@
use Sabre\HTTP\ClientHttpException;
use Sabre\DAV\Exception\InsufficientStorage;
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
+use Psr\Http\Message\ResponseInterface;
/**
* Class DAV
diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php
index b20aa28efd2f..76ed5b30878b 100644
--- a/lib/private/Http/Client/Client.php
+++ b/lib/private/Http/Client/Client.php
@@ -62,23 +62,24 @@ private function setDefaultOptions() {
return;
}
$this->configured = true;
+ $config = $this->client->getConfig();
// Either use user bundle or the system bundle if nothing is specified
if ($this->certificateManager->listCertificates() !== []) {
- $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath());
+ $config['verify'] = $this->certificateManager->getAbsoluteBundlePath();
} else {
// If the instance is not yet setup we need to use the static path as
// $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate
// a view
if ($this->config->getSystemValue('installed', false) && !\OCP\Util::needUpgrade()) {
- $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null));
+ $config['verify'] = $this->certificateManager->getAbsoluteBundlePath(null);
} else {
- $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
+ $config['verify'] = \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
}
}
- $this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
+ $config['headers/User-Agent'] = 'ownCloud Server Crawler';
if ($this->getProxyUri() !== '') {
- $this->client->setDefaultOption('proxy', $this->getProxyUri());
+ $config['proxy'] = $this->getProxyUri();
}
}
@@ -199,6 +200,10 @@ public function head($uri, $options = []) {
*/
public function post($uri, array $options = []) {
$this->setDefaultOptions();
+ if (isset($options['body']) && \is_array($options['body'])) {
+ $options['form_params'] = $options['body'];
+ unset($options['body']);
+ }
$response = $this->client->post($uri, $options);
return new Response($response);
}
diff --git a/lib/private/Http/Client/Response.php b/lib/private/Http/Client/Response.php
index 17677efdaf7c..2ab3a8334c4b 100644
--- a/lib/private/Http/Client/Response.php
+++ b/lib/private/Http/Client/Response.php
@@ -23,7 +23,7 @@
namespace OC\Http\Client;
use OCP\Http\Client\IResponse;
-use GuzzleHttp\Message\Response as GuzzleResponse;
+use Psr\Http\Message\ResponseInterface;
/**
* Class Response
@@ -31,7 +31,7 @@
* @package OC\Http
*/
class Response implements IResponse {
- /** @var GuzzleResponse */
+ /** @var ResponseInterface */
private $response;
/**
@@ -40,10 +40,10 @@ class Response implements IResponse {
private $stream;
/**
- * @param GuzzleResponse $response
+ * @param ResponseInterface $response
* @param bool $stream
*/
- public function __construct(GuzzleResponse $response, $stream = false) {
+ public function __construct(ResponseInterface $response, $stream = false) {
$this->response = $response;
$this->stream = $stream;
}
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php
index 9bb2143e9d9a..6e95e86bb484 100644
--- a/tests/Settings/Controller/CheckSetupControllerTest.php
+++ b/tests/Settings/Controller/CheckSetupControllerTest.php
@@ -29,11 +29,13 @@
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
+use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
+use Psr\Http\Message\ResponseInterface;
use Test\TestCase;
/**
@@ -63,28 +65,28 @@ class CheckSetupControllerTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->request = $this->getMockBuilder('\OCP\IRequest')
+ $this->request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()->getMock();
- $this->config = $this->getMockBuilder('\OCP\IConfig')
+ $this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()->getMock();
- $this->config = $this->getMockBuilder('\OCP\IConfig')
+ $this->config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()->getMock();
- $this->clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
+ $this->clientService = $this->getMockBuilder(IClientService::class)
->disableOriginalConstructor()->getMock();
- $this->util = $this->getMockBuilder('\OC_Util')
+ $this->util = $this->getMockBuilder(\OC_Util::class)
->disableOriginalConstructor()->getMock();
- $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
+ $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)
->disableOriginalConstructor()->getMock();
- $this->l10n = $this->getMockBuilder('\OCP\IL10N')
+ $this->l10n = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()->getMock();
$this->l10n->expects($this->any())
->method('t')
->will($this->returnCallback(function ($message, array $replace) {
return \vsprintf($message, $replace);
}));
- $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
+ $this->checker = $this->getMockBuilder(Checker::class)
->disableOriginalConstructor()->getMock();
- $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
+ $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
->setConstructorArgs([
'settings',
$this->request,
@@ -118,7 +120,7 @@ public function testIsInternetConnectionWorkingCorrectly() {
->with('has_internet_connection', true)
->will($this->returnValue(true));
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ $client = $this->getMockBuilder(IClient::class)
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
@@ -145,7 +147,7 @@ public function testIsInternetConnectionHttpsFail() {
->with('has_internet_connection', true)
->will($this->returnValue(true));
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ $client = $this->getMockBuilder(IClient::class)
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
@@ -170,7 +172,7 @@ public function testIsInternetConnectionHttpFail() {
->with('has_internet_connection', true)
->will($this->returnValue(true));
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ $client = $this->getMockBuilder(IClient::class)
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
@@ -305,7 +307,7 @@ public function testCheck() {
->method('getRemoteAddress')
->willReturn('4.3.2.1');
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ $client = $this->getMockBuilder(IClient::class)
->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))
->method('get')
@@ -359,7 +361,7 @@ public function testCheck() {
}
public function testGetCurlVersion() {
- $checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
+ $checkSetupController = $this->getMockBuilder(CheckSetupController::class)
->setConstructorArgs([
'settings',
$this->request,
@@ -449,12 +451,12 @@ public function testIsBuggyNss400() {
->expects($this->once())
->method('getCurlVersion')
->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b']));
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ $client = $this->getMockBuilder(IClient::class)
->disableOriginalConstructor()->getMock();
/** @var ClientException | \PHPUnit\Framework\MockObject\MockObject $exception */
- $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException')
+ $exception = $this->getMockBuilder(ClientException::class)
->disableOriginalConstructor()->getMock();
- $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface')
+ $response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()->getMock();
$response->expects($this->once())
->method('getStatusCode')
@@ -483,12 +485,12 @@ public function testIsBuggyNss200() {
->expects($this->once())
->method('getCurlVersion')
->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b']));
- $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
+ $client = $this->getMockBuilder(IClient::class)
->disableOriginalConstructor()->getMock();
/** @var ClientException | \PHPUnit\Framework\MockObject\MockObject $exception */
- $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException')
+ $exception = $this->getMockBuilder(ClientException::class)
->disableOriginalConstructor()->getMock();
- $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface')
+ $response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()->getMock();
$response->expects($this->once())
->method('getStatusCode')
diff --git a/tests/TestHelpers/DownloadHelper.php b/tests/TestHelpers/DownloadHelper.php
index 93a71e99a9ea..8fd480d52545 100644
--- a/tests/TestHelpers/DownloadHelper.php
+++ b/tests/TestHelpers/DownloadHelper.php
@@ -21,7 +21,7 @@
*/
namespace TestHelpers;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
/**
* Helper for Downloads
diff --git a/tests/TestHelpers/HttpRequestHelper.php b/tests/TestHelpers/HttpRequestHelper.php
index c0959bbc4946..98b304bdab22 100644
--- a/tests/TestHelpers/HttpRequestHelper.php
+++ b/tests/TestHelpers/HttpRequestHelper.php
@@ -25,7 +25,8 @@
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\BadResponseException;
-use GuzzleHttp\Message\ResponseInterface;
+use GuzzleHttp\Psr7\Request;
+use Psr\Http\Message\ResponseInterface;
use SimpleXMLElement;
use Sabre\Xml\LibXMLException;
use Sabre\Xml\Reader;
@@ -160,7 +161,15 @@ public static function createRequest(
$options['auth'] = [$user, $password];
}
if ($body !== null) {
- $options['body'] = $body;
+ if (\is_array($body)) {
+ // the array of 'form_params' get converted into a body by the
+ // client, which uses http_build_query to do it.
+ $options['form_params'] = $body;
+ } else {
+ // just use the ordinary body provided as-is.
+ // e.g. the caller might have already built a JSON-encoded string
+ $options['body'] = $body;
+ }
}
if ($config !== null) {
$options['config'] = $config;
@@ -320,7 +329,9 @@ public static function delete(
* @return SimpleXMLElement
*/
public static function getResponseXml($response) {
- return $response->xml();
+ // rewind just to make sure we can re-parse it in case it was parsed already...
+ $response->getBody()->rewind();
+ return new SimpleXMLElement($response->getBody()->getContents());
}
/**
diff --git a/tests/TestHelpers/MoveCopyHelper.php b/tests/TestHelpers/MoveCopyHelper.php
index 8841049cbd5c..c646ddff7288 100644
--- a/tests/TestHelpers/MoveCopyHelper.php
+++ b/tests/TestHelpers/MoveCopyHelper.php
@@ -21,7 +21,7 @@
*/
namespace TestHelpers;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
/**
* Helper for move and copy files
diff --git a/tests/TestHelpers/OcsApiHelper.php b/tests/TestHelpers/OcsApiHelper.php
index 937ebc9b6ae2..1081fdf86428 100644
--- a/tests/TestHelpers/OcsApiHelper.php
+++ b/tests/TestHelpers/OcsApiHelper.php
@@ -21,8 +21,8 @@
*/
namespace TestHelpers;
-use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Client;
+use Psr\Http\Message\ResponseInterface;
/**
* Helper to make requests to the OCS API
diff --git a/tests/TestHelpers/SetupHelper.php b/tests/TestHelpers/SetupHelper.php
index 67affb19cec6..24cfc4521dec 100644
--- a/tests/TestHelpers/SetupHelper.php
+++ b/tests/TestHelpers/SetupHelper.php
@@ -676,9 +676,10 @@ public static function runOcc(
}
$return = [];
- $return['code'] = $result->xml()->xpath("//ocs/data/code");
- $return['stdOut'] = $result->xml()->xpath("//ocs/data/stdOut");
- $return['stdErr'] = $result->xml()->xpath("//ocs/data/stdErr");
+ $resultXml = \simplexml_load_string($result->getBody()->getContents());
+ $return['code'] = $resultXml->xpath("//ocs/data/code");
+ $return['stdOut'] = $resultXml->xpath("//ocs/data/stdOut");
+ $return['stdErr'] = $resultXml->xpath("//ocs/data/stdErr");
if (!\is_a($return['code'][0], "SimpleXMLElement")
|| !\is_a($return['stdOut'][0], "SimpleXMLElement")
diff --git a/tests/TestHelpers/SharingHelper.php b/tests/TestHelpers/SharingHelper.php
index e2a3a5bce04f..014ff2f34a54 100644
--- a/tests/TestHelpers/SharingHelper.php
+++ b/tests/TestHelpers/SharingHelper.php
@@ -21,7 +21,7 @@
*/
namespace TestHelpers;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
/**
* manage Shares via OCS API
diff --git a/tests/TestHelpers/TagsHelper.php b/tests/TestHelpers/TagsHelper.php
index 48181574cbb5..884c13be3b43 100644
--- a/tests/TestHelpers/TagsHelper.php
+++ b/tests/TestHelpers/TagsHelper.php
@@ -21,8 +21,8 @@
*/
namespace TestHelpers;
-use GuzzleHttp\Message\ResponseInterface;
use Exception;
+use Psr\Http\Message\ResponseInterface;
use SimpleXMLElement;
/**
diff --git a/tests/TestHelpers/Unit/DeleteHelperTest.php b/tests/TestHelpers/Unit/DeleteHelperTest.php
index 00aa9dfe0e20..accbb6d91b08 100644
--- a/tests/TestHelpers/Unit/DeleteHelperTest.php
+++ b/tests/TestHelpers/Unit/DeleteHelperTest.php
@@ -22,14 +22,17 @@
use TestHelpers\DeleteHelper;
use GuzzleHttp\Client;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Message\Response;
-use GuzzleHttp\Subscriber\History;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Middleware;
+use GuzzleHttp\Psr7\Response;
+use GuzzleHttp\Psr7\Request;
/**
* Unit tests for TestHelpers\DeleteHelper;
*/
class DeleteHelperTest extends PHPUnit\Framework\TestCase {
+ private $container = [];
/**
* Setup http client, mock requests, and attach history
@@ -37,16 +40,14 @@ class DeleteHelperTest extends PHPUnit\Framework\TestCase {
* @return void
*/
public function setUp() {
- $mock = new Mock(
+ $mock = new MockHandler(
[ new Response(204, [])]
);
+ $handler = HandlerStack::create($mock);
+ $history = Middleware::history($this->container);
+ $handler->push($history);
- $this->client = new Client();
-
- $this->history = new History();
-
- $this->client->getEmitter()->attach($mock);
- $this->client->getEmitter()->attach($this->history);
+ $this->client = new Client(['handler' => $handler]);
}
/**
@@ -66,13 +67,16 @@ public function testDeleteHelperWithOlderDavVersion() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
$this->assertEquals(
'http://localhost/remote.php/webdav/secret/file.txt',
- $lastRequest->getUrl()
+ $lastRequest->getUri()
);
$this->assertEquals('DELETE', $lastRequest->getMethod());
- $this->assertNull($lastRequest->getBody());
+ $this->assertEquals('', $lastRequest->getBody()->getContents());
$this->assertEquals(
['Basic ' . \base64_encode('user:password')],
@@ -97,13 +101,16 @@ public function testDeleteHelperWithNewerDavVersion() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
$this->assertEquals(
'http://localhost/remote.php/dav/files/user/secret/file.txt',
- $lastRequest->getUrl()
+ $lastRequest->getUri()
);
$this->assertEquals('DELETE', $lastRequest->getMethod());
- $this->assertNull($lastRequest->getBody());
+ $this->assertEquals('', $lastRequest->getBody()->getContents());
$this->assertEquals(
['Basic ' . \base64_encode('user:password')],
@@ -129,7 +136,10 @@ public function testDeleteHelperSendsWithGivenHeaders() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
$this->assertArrayHasKey("Cache-Control", $lastRequest->getHeaders());
// Guzzle adds it to the array
diff --git a/tests/TestHelpers/Unit/WebDavHelperTest.php b/tests/TestHelpers/Unit/WebDavHelperTest.php
index d34871cbd158..436fb7d1cc3a 100644
--- a/tests/TestHelpers/Unit/WebDavHelperTest.php
+++ b/tests/TestHelpers/Unit/WebDavHelperTest.php
@@ -22,14 +22,18 @@
use TestHelpers\WebDavHelper;
use GuzzleHttp\Client;
-use GuzzleHttp\Subscriber\Mock;
-use GuzzleHttp\Message\Response;
-use GuzzleHttp\Subscriber\History;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Middleware;
+use GuzzleHttp\Psr7\Response;
+use GuzzleHttp\Psr7\Request;
/**
* Test for WebDavHelper
*/
class WebDavHelperTest extends PHPUnit\Framework\TestCase {
+ private $container = [];
+
/**
* Setup mock response, client and listen for all requests
* through history.
@@ -39,15 +43,14 @@ class WebDavHelperTest extends PHPUnit\Framework\TestCase {
public function setUp() {
// mocks is not used, but is required. Else it will try to
// contact original server and will fail our tests.
- $mock = new Mock(
+ $mock = new MockHandler(
[new Response(200, []),]
);
+ $handler = HandlerStack::create($mock);
+ $history = Middleware::history($this->container);
+ $handler->push($history);
- $this->client = new Client();
- $this->history = new History();
-
- $this->client->getEmitter()->attach($mock);
- $this->client->getEmitter()->attach($this->history);
+ $this->client = new Client(['handler' => $handler]);
}
/**
@@ -75,11 +78,14 @@ public function testUrlIsSanitizedByMakeDavRequestForNewerDav() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
$this->assertEquals(
'http://own.cloud/core/remote.php/webdav/folder/file.txt',
- $lastRequest->getUrl()
+ $lastRequest->getUri()
);
$this->assertEquals('GET', $lastRequest->getMethod());
$this->assertEquals(
@@ -113,11 +119,14 @@ public function testUrlIsSanitizedByMakeDavRequestForOlderDavPath() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
$this->assertEquals(
'http://own.cloud/core/remote.php/dav/files/user1/folder/file.txt',
- $lastRequest->getUrl()
+ $lastRequest->getUri()
);
$this->assertEquals('GET', $lastRequest->getMethod());
}
@@ -147,11 +156,14 @@ public function testMakeDavRequestReplacesAsteriskAndHashesOnUrls() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
$this->assertEquals(
'http://own.cloud/core/remote.php/dav/files/user1/folder/file%3Fq=hello%23newfile',
- $lastRequest->getUrl()
+ $lastRequest->getUri()
);
// not just the link, but `Destination` header should have also been replaced
@@ -186,7 +198,10 @@ public function testMakeDavRequestOnBearerAuthorization() {
$this->client
);
- $lastRequest = $this->history->getLastRequest();
+ /**
+ * @var Request $lastRequest
+ */
+ $lastRequest = $this->container[0]['request'];
// no way to know that $user and $password is set to null, except confirming that
// the Authorization is `Bearer`. If it would have gotten username and password,
diff --git a/tests/TestHelpers/UploadHelper.php b/tests/TestHelpers/UploadHelper.php
index b8bbe81d1705..0af1076ed5b7 100644
--- a/tests/TestHelpers/UploadHelper.php
+++ b/tests/TestHelpers/UploadHelper.php
@@ -21,8 +21,7 @@
*/
namespace TestHelpers;
-use GuzzleHttp\Message\ResponseInterface;
-use GuzzleHttp\Stream\Stream;
+use Psr\Http\Message\ResponseInterface;
/**
* Helper for Uploads
@@ -64,7 +63,7 @@ public static function upload(
//simple upload with no chunking
if ($chunkingVersion === null) {
- $data = Stream::factory(\fopen($source, 'r'));
+ $data = \file_get_contents($source);
return WebDavHelper::makeDavRequest(
$baseUrl,
$user,
@@ -104,7 +103,6 @@ public static function upload(
//upload chunks
foreach ($chunks as $index => $chunk) {
- $data = Stream::factory($chunk);
if ($chunkingVersion === 1) {
$filename = $destination . "-" . $chunkingId . "-" .
\count($chunks) . '-' . ( string ) $index;
@@ -120,7 +118,7 @@ public static function upload(
"PUT",
$filename,
$headers,
- $data,
+ $chunk,
null,
$davPathVersionToUse,
$davRequestType
diff --git a/tests/TestHelpers/UserHelper.php b/tests/TestHelpers/UserHelper.php
index 8b78a5a5db62..03f08cfca041 100644
--- a/tests/TestHelpers/UserHelper.php
+++ b/tests/TestHelpers/UserHelper.php
@@ -22,8 +22,8 @@
namespace TestHelpers;
use GuzzleHttp\BatchResults;
-use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Client;
+use Psr\Http\Message\ResponseInterface;
/**
* Helper to administrate users (and groups) through the provisioning API
diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php
index 08258d68e893..1707a3e61b43 100644
--- a/tests/TestHelpers/WebDavHelper.php
+++ b/tests/TestHelpers/WebDavHelper.php
@@ -22,10 +22,9 @@
namespace TestHelpers;
use Exception;
-use GuzzleHttp\Message\ResponseInterface;
-use GuzzleHttp\Stream\Stream;
-use GuzzleHttp\Stream\StreamInterface;
use InvalidArgumentException;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\StreamInterface;
use SimpleXMLElement;
/**
@@ -52,21 +51,26 @@ public static function getFileIdForPath(
$password,
$path
) {
- $body = Stream::factory(
- '
+ $body
+ = '
-'
- );
+';
$response = self::makeDavRequest(
$baseUrl, $user, $password, "PROPFIND", $path, null, $body
);
- \preg_match('/\(\d+)\<\/oc:fileid\>/', $response, $matches);
+ \preg_match(
+ '/\(\d+)\<\/oc:fileid\>/',
+ $response->getBody()->getContents(),
+ $matches
+ );
+
if (!isset($matches[1])) {
throw new Exception("could not find fileId of $path");
}
+
return $matches[1];
}
@@ -248,7 +252,7 @@ public static function listFolder(
* @param string $method PUT, GET, DELETE, etc.
* @param string $path
* @param array $headers
- * @param StreamInterface $body
+ * @param string|null|resource|StreamInterface $body
* @param string $requestBody
* @param int $davPathVersionToUse (1|2)
* @param string $type of request
@@ -302,11 +306,9 @@ public static function makeDavRequest(
foreach ($headers as $key => $value) {
//? and # need to be encoded in the Destination URL
if ($key === "Destination") {
- $value = \str_replace(
+ $headers[$key] = \str_replace(
$urlSpecialChar[0], $urlSpecialChar[1], $value
);
- $headers[$key] = $value;
- break;
}
}
}
diff --git a/tests/acceptance/features/bootstrap/BasicStructure.php b/tests/acceptance/features/bootstrap/BasicStructure.php
index ccb92d485e8e..d8f5af46c46a 100644
--- a/tests/acceptance/features/bootstrap/BasicStructure.php
+++ b/tests/acceptance/features/bootstrap/BasicStructure.php
@@ -24,7 +24,7 @@
use Behat\Gherkin\Node\TableNode;
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use GuzzleHttp\Cookie\CookieJar;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcsApiHelper;
use TestHelpers\SetupHelper;
use TestHelpers\HttpRequestHelper;
diff --git a/tests/acceptance/features/bootstrap/CalDavContext.php b/tests/acceptance/features/bootstrap/CalDavContext.php
index e8042c6f9154..06c393d9528b 100644
--- a/tests/acceptance/features/bootstrap/CalDavContext.php
+++ b/tests/acceptance/features/bootstrap/CalDavContext.php
@@ -22,8 +22,8 @@
require __DIR__ . '/../../../../lib/composer/autoload.php';
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
-use GuzzleHttp\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
+use Psr\Http\Message\ResponseInterface;
/**
* CalDav functions
diff --git a/tests/acceptance/features/bootstrap/CardDavContext.php b/tests/acceptance/features/bootstrap/CardDavContext.php
index d227bf48565c..784919b1d705 100644
--- a/tests/acceptance/features/bootstrap/CardDavContext.php
+++ b/tests/acceptance/features/bootstrap/CardDavContext.php
@@ -22,8 +22,8 @@
require __DIR__ . '/../../../../lib/composer/autoload.php';
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
-use GuzzleHttp\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
+use Psr\Http\Message\ResponseInterface;
/**
* CardDav functions
diff --git a/tests/acceptance/features/bootstrap/ChecksumContext.php b/tests/acceptance/features/bootstrap/ChecksumContext.php
index 78533dc31f17..818a07da0b5e 100644
--- a/tests/acceptance/features/bootstrap/ChecksumContext.php
+++ b/tests/acceptance/features/bootstrap/ChecksumContext.php
@@ -50,11 +50,8 @@ class ChecksumContext implements Context {
public function userUploadsFileToWithChecksumUsingTheAPI(
$user, $source, $destination, $checksum
) {
- $file = \GuzzleHttp\Stream\Stream::factory(
- \fopen(
- $this->featureContext->acceptanceTestsDirLocation() . $source,
- 'r'
- )
+ $file = \file_get_contents(
+ $this->featureContext->acceptanceTestsDirLocation() . $source
);
$response = $this->featureContext->makeDavRequest(
$user,
@@ -170,7 +167,7 @@ public function theWebdavChecksumOfViaPropfindShouldMatch($user, $path, $checksu
*/
public function theHeaderChecksumShouldMatch($checksum) {
$headerChecksum
- = $this->featureContext->getResponse()->getHeader('OC-Checksum');
+ = $this->featureContext->getResponse()->getHeader('OC-Checksum')[0];
if ($headerChecksum !== $checksum) {
throw new \Exception(
"Expected $checksum, got "
@@ -236,7 +233,6 @@ public function userUploadsChunkFileOfWithToWithChecksum(
$user, $num, $total, $data, $destination, $checksum
) {
$num -= 1;
- $data = \GuzzleHttp\Stream\Stream::factory($data);
$file = "$destination-chunking-42-$total-$num";
$response = $this->featureContext->makeDavRequest(
$user,
diff --git a/tests/acceptance/features/bootstrap/FavoritesContext.php b/tests/acceptance/features/bootstrap/FavoritesContext.php
index 625f6b60862a..33f44e16b73c 100644
--- a/tests/acceptance/features/bootstrap/FavoritesContext.php
+++ b/tests/acceptance/features/bootstrap/FavoritesContext.php
@@ -23,7 +23,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
use TestHelpers\WebDavHelper;
require_once 'bootstrap.php';
diff --git a/tests/acceptance/features/bootstrap/NotificationsCoreContext.php b/tests/acceptance/features/bootstrap/NotificationsCoreContext.php
index 549834f6ee1e..19482654f553 100644
--- a/tests/acceptance/features/bootstrap/NotificationsCoreContext.php
+++ b/tests/acceptance/features/bootstrap/NotificationsCoreContext.php
@@ -22,7 +22,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcsApiHelper;
require_once 'bootstrap.php';
diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php
index b9c7d29594bc..697e08a69392 100644
--- a/tests/acceptance/features/bootstrap/Provisioning.php
+++ b/tests/acceptance/features/bootstrap/Provisioning.php
@@ -20,7 +20,7 @@
*/
use Behat\Gherkin\Node\TableNode;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcsApiHelper;
use TestHelpers\SetupHelper;
use TestHelpers\UserHelper;
diff --git a/tests/acceptance/features/bootstrap/ShareesContext.php b/tests/acceptance/features/bootstrap/ShareesContext.php
index 04b124367f05..5e9696310ee3 100644
--- a/tests/acceptance/features/bootstrap/ShareesContext.php
+++ b/tests/acceptance/features/bootstrap/ShareesContext.php
@@ -25,7 +25,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
require_once 'bootstrap.php';
diff --git a/tests/acceptance/features/bootstrap/TagsContext.php b/tests/acceptance/features/bootstrap/TagsContext.php
index e2397ada5c80..d6df7d5020e2 100644
--- a/tests/acceptance/features/bootstrap/TagsContext.php
+++ b/tests/acceptance/features/bootstrap/TagsContext.php
@@ -23,7 +23,7 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
-use GuzzleHttp\Message\ResponseInterface;
+use Psr\Http\Message\ResponseInterface;
use TestHelpers\TagsHelper;
use TestHelpers\WebDavHelper;
use TestHelpers\HttpRequestHelper;
diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php
index bbfd092d0d73..8576a4af41bb 100644
--- a/tests/acceptance/features/bootstrap/WebDav.php
+++ b/tests/acceptance/features/bootstrap/WebDav.php
@@ -21,10 +21,11 @@
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
-use GuzzleHttp\Message\ResponseInterface;
use GuzzleHttp\Ring\Exception\ConnectException;
use GuzzleHttp\Stream\StreamInterface;
use Guzzle\Http\Exception\BadResponseException;
+use PHPUnit\Framework\Assert;
+use Psr\Http\Message\ResponseInterface;
use TestHelpers\OcsApiHelper;
use TestHelpers\SetupHelper;
use TestHelpers\UploadHelper;
@@ -940,7 +941,20 @@ public function theFollowingHeadersShouldBeSet(TableNode $table) {
$returnedHeader = $this->response->getHeader($headerName);
$expectedHeaderValue = $this->substituteInLineCodes($expectedHeaderValue);
- if ($returnedHeader !== $expectedHeaderValue) {
+ if (\is_array($returnedHeader)) {
+ if (empty($returnedHeader)) {
+ throw new \Exception(
+ \sprintf(
+ "Missing expected header '%s'",
+ $headerName
+ )
+ );
+ }
+ $headerValue = $returnedHeader[0];
+ } else {
+ $headerValue = $returnedHeader;
+ }
+ if ($headerValue !== $expectedHeaderValue) {
throw new \Exception(
\sprintf(
"Expected value '%s' for header '%s', got '%s'",
@@ -982,11 +996,13 @@ public function downloadedContentShouldStartWith($start) {
* @return void
*/
public function jobStatusValuesShouldMatchRegEx($user, $table) {
- $url = $this->response->getHeader("OC-JobStatus-Location");
+ $headerArray = $this->response->getHeader("OC-JobStatus-Location");
+ $url = $headerArray[0];
$url = $this->getBaseUrlWithoutPath() . $url;
$response = HttpRequestHelper::get($url, $user, $this->getPasswordForUser($user));
- $result = \json_decode($response->getBody()->getContents(), true);
- PHPUnit\Framework\Assert::assertNotNull($result, "'$response' is not valid JSON");
+ $contents = $response->getBody()->getContents();
+ $result = \json_decode($contents, true);
+ PHPUnit\Framework\Assert::assertNotNull($result, "'$contents' is not valid JSON");
foreach ($table->getTable() as $row) {
$expectedKey = $row[0];
PHPUnit\Framework\Assert::assertArrayHasKey(
@@ -1168,12 +1184,7 @@ public function checkElementList(
* @return void
*/
public function userUploadsAFileTo($user, $source, $destination) {
- $file = \GuzzleHttp\Stream\Stream::factory(
- \fopen(
- $this->acceptanceTestsDirLocation() . $source,
- 'r'
- )
- );
+ $file = \fopen($this->acceptanceTestsDirLocation() . $source, 'r');
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
$user, "PUT", $destination, [], $file
@@ -1400,7 +1411,7 @@ public function theHTTPStatusCodeOfAllUploadResponsesShouldBe($statusCode) {
PHPUnit\Framework\Assert::assertEquals(
$statusCode,
$response->getStatusCode(),
- 'Response for ' . $response->getEffectiveUrl() . ' did not return expected status code'
+ 'Response did not return expected status code'
);
}
}
@@ -1417,7 +1428,7 @@ public function theHTTPReasonPhraseOfAllUploadResponsesShouldBe($reasonPhrase) {
PHPUnit\Framework\Assert::assertEquals(
$reasonPhrase,
$response->getReasonPhrase(),
- 'Response for ' . $response->getEffectiveUrl() . ' did not return expected reason phrase'
+ 'Response did not return expected reason phrase'
);
}
}
@@ -1465,12 +1476,12 @@ public function theHTTPStatusCodeOfAllUploadResponsesShouldBeBetween(
PHPUnit\Framework\Assert::assertGreaterThanOrEqual(
$minStatusCode,
$response->getStatusCode(),
- 'Response for ' . $response->getEffectiveUrl() . ' did not return expected status code'
+ 'Response did not return expected status code'
);
PHPUnit\Framework\Assert::assertLessThanOrEqual(
$maxStatusCode,
$response->getStatusCode(),
- 'Response for ' . $response->getEffectiveUrl() . ' did not return expected status code'
+ 'Response did not return expected status code'
);
}
}
@@ -1577,10 +1588,9 @@ public function userUploadsAFileToOfBytes($user, $destination, $bytes) {
public function userUploadsAFileWithContentTo(
$user, $content, $destination
) {
- $file = \GuzzleHttp\Stream\Stream::factory($content);
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
- $user, "PUT", $destination, [], $file
+ $user, "PUT", $destination, [], $content
);
$this->lastUploadDeleteTime = \time();
return $this->response->getHeader('oc-fileid');
@@ -1600,14 +1610,13 @@ public function userUploadsAFileWithContentTo(
public function userUploadsAFileWithChecksumAndContentTo(
$user, $checksum, $content, $destination
) {
- $file = \GuzzleHttp\Stream\Stream::factory($content);
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
$user,
"PUT",
$destination,
['OC-Checksum' => $checksum],
- $file
+ $content
);
$this->lastUploadDeleteTime = \time();
}
@@ -1823,7 +1832,6 @@ public function userUploadsChunkedFile(
$user, $num, $total, $data, $destination
) {
$num -= 1;
- $data = \GuzzleHttp\Stream\Stream::factory($data);
$file = "$destination-chunking-42-$total-$num";
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest(
@@ -1922,7 +1930,6 @@ public function userCreatesANewChunkingUploadWithId($user, $id) {
* @return void
*/
public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id) {
- $data = \GuzzleHttp\Stream\Stream::factory($data);
$destination = "/uploads/$user/$id/$num";
$this->response = $this->makeDavRequest(
$user, 'PUT', $destination, [], $data, "uploads"
@@ -2104,12 +2111,17 @@ public function theFollowingHeadersShouldNotBeSet(TableNode $table) {
foreach ($table->getTable() as $header) {
$headerName = $header[0];
$headerValue = $this->response->getHeader($headerName);
- //Note: according to the documentation of getHeader it must return null
- //if the header does not exist, but its returning an empty string
+ //Note: getHeader returns an empty array if the named header does not exist
+ if (isset($headerValue[0])) {
+ $headerValue0 = $headerValue[0];
+ } else {
+ $headerValue0 = '';
+ }
+
PHPUnit\Framework\Assert::assertEmpty(
$headerValue,
"header $headerName should not exist " .
- "but does and is set to $headerValue"
+ "but does and is set to $headerValue0"
);
}
}
@@ -2130,8 +2142,9 @@ public function headersShouldMatchRegularExpressions(TableNode $table) {
$expectedHeaderValue, ['preg_quote' => ['/'] ]
);
- $returnedHeader = $this->response->getHeader($headerName);
- PHPUnit\Framework\Assert::assertNotFalse(
+ $returnedHeaders = $this->response->getHeader($headerName);
+ $returnedHeader = $returnedHeaders[0];
+ Assert::assertNotFalse(
(bool)\preg_match($expectedHeaderValue, $returnedHeader),
"'$expectedHeaderValue' does not match '$returnedHeader'"
);
@@ -2201,7 +2214,7 @@ public function userStoresFileIdForPath($user, $path) {
*/
public function userFileShouldHaveStoredId($user, $path) {
$currentFileID = $this->getFileIdForPath($user, $path);
- PHPUnit\Framework\Assert::assertEquals(
+ Assert::assertEquals(
$currentFileID, $this->storedFileID
);
}
@@ -2240,12 +2253,12 @@ public function propfindResultShouldContainEntries(
$expectedFile[0]
);
if ($should) {
- PHPUnit\Framework\Assert::assertNotEmpty(
+ Assert::assertNotEmpty(
$fileFound,
"response does not contain the entry '$expectedFile[0]'"
);
} else {
- PHPUnit\Framework\Assert::assertFalse(
+ Assert::assertFalse(
$fileFound,
"response does contain the entry '$expectedFile[0]' but should not"
);
@@ -2272,7 +2285,7 @@ public function propfindResultShouldContainNumEntries($numFiles) {
if ($multistatusResults === null) {
$multistatusResults = [];
}
- PHPUnit\Framework\Assert::assertEquals((int)$numFiles, \count($multistatusResults));
+ Assert::assertEquals((int)$numFiles, \count($multistatusResults));
}
/**
@@ -2290,7 +2303,7 @@ public function theSearchResultOfShouldContainAnyOfTheseEntries(
$elementRows = $expectedFiles->getRowsHash();
$resultEntries = $this->findEntryFromPropfindResponse();
foreach ($resultEntries as $resultEntry) {
- PHPUnit\Framework\Assert::assertArrayHasKey($resultEntry, $elementRows);
+ Assert::assertArrayHasKey($resultEntry, $elementRows);
}
}
@@ -2313,10 +2326,10 @@ public function findEntryFromPropfindResponse($entryNameToSearch = null) {
HttpRequestHelper::parseResponseAsXml($this->response)
);
}
- $fullWebDavPath = \ltrim(
- \parse_url($this->response->getEffectiveUrl(), PHP_URL_PATH) . "/",
- "/"
- );
+ // The responseXml has item with name "{DAV:}href" and the value is
+ // the WebDav path of the top-level entry that was requested
+ $davHref = $this->responseXml['value'][0]['value'][0]['value'];
+ $fullWebDavPath = \ltrim($davHref, "/");
$multistatusResults = $this->responseXml["value"];
$results = [];
if ($multistatusResults !== null) {
diff --git a/tests/lib/Files/Storage/DavTest.php b/tests/lib/Files/Storage/DavTest.php
index 6a153dde1a06..99ac9f4ac218 100644
--- a/tests/lib/Files/Storage/DavTest.php
+++ b/tests/lib/Files/Storage/DavTest.php
@@ -34,6 +34,8 @@
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IWebDavClientService;
use OCP\Lock\LockedException;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
use Sabre\DAV\Client;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\InsufficientStorage;
@@ -102,7 +104,7 @@ protected function setUp() {
$this->davClient = $this->createMock(Client::class);
$this->webDavClientService->method('newClient')->willReturn($this->davClient);
- $this->instance = $this->getMockBuilder(\OC\Files\Storage\DAV::class)
+ $this->instance = $this->getMockBuilder(DAV::class)
->setConstructorArgs([[
'user' => 'davuser',
'password' => 'davpassword',
@@ -152,7 +154,7 @@ public function testInstantiateWebDavClient($secure, $protocol) {
])
->willReturn($this->davClient);
- $this->instance = new \OC\Files\Storage\DAV([
+ $this->instance = new DAV([
'user' => 'davuser',
'password' => 'davpassword',
'host' => 'davhost',
@@ -188,7 +190,7 @@ public function invalidConfigDataProvider() {
* @expectedException \InvalidArgumentException
*/
public function testInstantiateWebDavClientInvalidConfig($params) {
- new \OC\Files\Storage\DAV($params);
+ new DAV($params);
}
private function createClientHttpException($statusCode) {
@@ -199,15 +201,15 @@ private function createClientHttpException($statusCode) {
}
private function createGuzzleClientException($statusCode) {
- $request = $this->createMock(\GuzzleHttp\Message\RequestInterface::class);
- $response = $this->createMock(\GuzzleHttp\Message\ResponseInterface::class);
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$response->method('getStatusCode')->willReturn($statusCode);
return new ClientException('ClientException', $request, $response);
}
private function createGuzzleServerException($statusCode) {
- $request = $this->createMock(\GuzzleHttp\Message\RequestInterface::class);
- $response = $this->createMock(\GuzzleHttp\Message\ResponseInterface::class);
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$response->method('getStatusCode')->willReturn($statusCode);
return new ServerException('ServerException', $request, $response);
}
@@ -222,7 +224,7 @@ public function convertExceptionDataProvider() {
];
$testCases = [
- [new \Sabre\DAV\Exception\Forbidden('Forbidden'), \Sabre\DAV\Exception\Forbidden::class],
+ [new Forbidden('Forbidden'), Forbidden::class],
[new \InvalidArgumentException(), StorageNotAvailableException::class],
[new StorageNotAvailableException(), StorageNotAvailableException::class],
[new StorageInvalidException(), StorageInvalidException::class],
@@ -239,7 +241,7 @@ public function convertExceptionDataProvider() {
$testCases[] = [
new ServerException(
'ServerException with no response',
- $this->createMock(\GuzzleHttp\Message\RequestInterface::class),
+ $this->createMock(RequestInterface::class),
null
),
StorageNotAvailableException::class
@@ -517,7 +519,7 @@ public function testUnlinkException() {
}
public function testFopenRead() {
- $response = $this->createMock(\GuzzleHttp\Message\ResponseInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$response->method('getStatusCode')->willReturn(Http::STATUS_OK);
$response->method('getBody')->willReturn(\fopen('data://text/plain,response body', 'r'));
@@ -573,7 +575,7 @@ public function testFopenReadException() {
* @expectedException \OCP\Lock\LockedException
*/
public function testFopenReadLockedException() {
- $response = $this->createMock(\GuzzleHttp\Message\ResponseInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$response->method('getStatusCode')->willReturn(Http::STATUS_LOCKED);
$response->method('getBody')->willReturn(\fopen('data://text/plain,response body', 'r'));
diff --git a/tests/lib/Http/Client/ClientTest.php b/tests/lib/Http/Client/ClientTest.php
index 83eeee64220f..676cc0227ef8 100644
--- a/tests/lib/Http/Client/ClientTest.php
+++ b/tests/lib/Http/Client/ClientTest.php
@@ -8,15 +8,19 @@
namespace Test\Http\Client;
-use GuzzleHttp\Message\Response;
+use GuzzleHttp\Client as GuzzleClient;
use OC\Http\Client\Client;
+use OCP\ICertificateManager;
use OCP\IConfig;
+use Psr\Http\Message\ResponseInterface;
/**
* Class ClientTest
*/
class ClientTest extends \Test\TestCase {
- /** @var \GuzzleHttp\Client */
+ /** @var ResponseInterface */
+ private $response;
+ /** @var GuzzleClient */
private $guzzleClient;
/** @var Client */
private $client;
@@ -25,11 +29,15 @@ class ClientTest extends \Test\TestCase {
public function setUp() {
parent::setUp();
- $this->config = $this->createMock('\OCP\IConfig');
- $this->guzzleClient = $this->getMockBuilder('\GuzzleHttp\Client')
+ $this->config = $this->createMock(IConfig::class);
+ $this->response = $this->createMock(ResponseInterface::class);
+ $this->response->method('getStatusCode')
+ ->willReturn(1337);
+ $this->guzzleClient = $this->getMockBuilder(GuzzleClient::class)
->disableOriginalConstructor()
+ ->setMethods(['get', 'post', 'put', 'delete', 'options'])
->getMock();
- $certificateManager = $this->createMock('\OCP\ICertificateManager');
+ $certificateManager = $this->createMock(ICertificateManager::class);
$this->client = new Client(
$this->config,
$certificateManager,
@@ -81,31 +89,31 @@ public function testGetProxyUriProxyHostWithPassword() {
public function testGet() {
$this->guzzleClient->method('get')
- ->willReturn(new Response(1337));
+ ->willReturn($this->response);
$this->assertEquals(1337, $this->client->get('http://localhost/', [])->getStatusCode());
}
public function testPost() {
$this->guzzleClient->method('post')
- ->willReturn(new Response(1337));
+ ->willReturn($this->response);
$this->assertEquals(1337, $this->client->post('http://localhost/', [])->getStatusCode());
}
public function testPut() {
$this->guzzleClient->method('put')
- ->willReturn(new Response(1337));
+ ->willReturn($this->response);
$this->assertEquals(1337, $this->client->put('http://localhost/', [])->getStatusCode());
}
public function testDelete() {
$this->guzzleClient->method('delete')
- ->willReturn(new Response(1337));
+ ->willReturn($this->response);
$this->assertEquals(1337, $this->client->delete('http://localhost/', [])->getStatusCode());
}
public function testOptions() {
$this->guzzleClient->method('options')
- ->willReturn(new Response(1337));
+ ->willReturn($this->response);
$this->assertEquals(1337, $this->client->options('http://localhost/', [])->getStatusCode());
}
}
diff --git a/tests/lib/Http/Client/ResponseTest.php b/tests/lib/Http/Client/ResponseTest.php
index ba448a326bb0..cc4c3d8a518d 100644
--- a/tests/lib/Http/Client/ResponseTest.php
+++ b/tests/lib/Http/Client/ResponseTest.php
@@ -8,8 +8,8 @@
namespace Test\Http\Client;
-use GuzzleHttp\Message\Response as GuzzleResponse;
use OC\Http\Client\Response;
+use Psr\Http\Message\ResponseInterface;
/**
* Class ResponseTest
@@ -17,21 +17,27 @@
class ResponseTest extends \Test\TestCase {
/** @var Response */
private $response;
- /** @var GuzzleResponse */
+ /** @var ResponseInterface */
private $guzzleResponse;
public function setUp() {
parent::setUp();
- $this->guzzleResponse = new GuzzleResponse(1337);
+ $this->guzzleResponse = $this->createMock(ResponseInterface::class);
$this->response = new Response($this->guzzleResponse);
}
public function testGetStatusCode() {
+ $this->guzzleResponse->expects($this->once())
+ ->method('getStatusCode')
+ ->willReturn(1337);
$this->assertEquals(1337, $this->response->getStatusCode());
}
public function testGetHeader() {
- $this->guzzleResponse->setHeader('bar', 'foo');
+ $this->guzzleResponse->expects($this->once())
+ ->method('getHeader')
+ ->with('bar')
+ ->willReturn('foo');
$this->assertEquals('foo', $this->response->getHeader('bar'));
}
}