From 97167d7b906ea24b12684f3a6c8d7e689d6ec0fb Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 7 Oct 2020 21:49:12 +0200 Subject: [PATCH] Replace IHTTPResult for CurlResult usages --- src/Model/GServer.php | 13 +++++++------ src/Network/CurlResult.php | 2 +- src/Network/IHTTPRequest.php | 6 +++--- tests/src/Core/InstallerTest.php | 26 +++++++++++++------------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 323a23f49..ac86ef38b 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -30,7 +30,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module\Register; -use Friendica\Network\CurlResult; +use Friendica\Network\IHTTPResult; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -630,18 +630,19 @@ class GServer /** * Detect server type by using the nodeinfo data * - * @param string $url address of the server - * @param CurlResult $curlResult + * @param string $url address of the server + * @param IHTTPResult $httpResult + * * @return array Server data * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - private static function fetchNodeinfo(string $url, CurlResult $curlResult) + private static function fetchNodeinfo(string $url, IHTTPResult $httpResult) { - if (!$curlResult->isSuccess()) { + if (!$httpResult->isSuccess()) { return []; } - $nodeinfo = json_decode($curlResult->getBody(), true); + $nodeinfo = json_decode($httpResult->getBody(), true); if (!is_array($nodeinfo) || empty($nodeinfo['links'])) { return []; diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index 072ab15c2..1187e45eb 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -101,7 +101,7 @@ class CurlResult implements IHTTPResult * * @param string $url optional URL * - * @return CurlResult a CURL with error response + * @return IHTTPResult a CURL with error response * @throws InternalServerErrorException */ public static function createErrorCurl($url = '') diff --git a/src/Network/IHTTPRequest.php b/src/Network/IHTTPRequest.php index 3ebcc5dc1..3f9b7f27a 100644 --- a/src/Network/IHTTPRequest.php +++ b/src/Network/IHTTPRequest.php @@ -57,7 +57,7 @@ interface IHTTPRequest * @param string $accept_content supply Accept: header with 'accept_content' as the value * @param string $cookiejar Path to cookie jar file * - * @return CurlResult With all relevant information, 'body' contains the actual fetched content. + * @return IHTTPResult With all relevant information, 'body' contains the actual fetched content. */ public function fetchFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = ''); @@ -76,7 +76,7 @@ interface IHTTPRequest * 'cookiejar' => path to cookie jar file * 'header' => header array * - * @return CurlResult + * @return IHTTPResult */ public function get(string $url, bool $binary = false, array $opts = []); @@ -88,7 +88,7 @@ interface IHTTPRequest * @param array $headers HTTP headers * @param int $timeout The timeout in seconds, default system config value or 60 seconds * - * @return CurlResult The content + * @return IHTTPResult The content */ public function post(string $url, $params, array $headers = [], int $timeout = 0); diff --git a/tests/src/Core/InstallerTest.php b/tests/src/Core/InstallerTest.php index 00879680e..37a754bc9 100644 --- a/tests/src/Core/InstallerTest.php +++ b/tests/src/Core/InstallerTest.php @@ -25,7 +25,7 @@ namespace Friendica\Core; use Dice\Dice; use Friendica\Core\Config\Cache; use Friendica\DI; -use Friendica\Network\CurlResult; +use Friendica\Network\IHTTPResult; use Friendica\Network\IHTTPRequest; use Friendica\Test\MockedTest; use Friendica\Test\Util\VFSTrait; @@ -297,14 +297,14 @@ class InstallerTest extends MockedTest $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); // Mocking the CURL Response - $curlResult = \Mockery::mock(CurlResult::class); - $curlResult + $IHTTPResult = \Mockery::mock(IHTTPResult::class); + $IHTTPResult ->shouldReceive('getReturnCode') ->andReturn('404'); - $curlResult + $IHTTPResult ->shouldReceive('getRedirectUrl') ->andReturn(''); - $curlResult + $IHTTPResult ->shouldReceive('getError') ->andReturn('test Error'); @@ -313,11 +313,11 @@ class InstallerTest extends MockedTest $networkMock ->shouldReceive('fetchFull') ->with('https://test/install/testrewrite') - ->andReturn($curlResult); + ->andReturn($IHTTPResult); $networkMock ->shouldReceive('fetchFull') ->with('http://test/install/testrewrite') - ->andReturn($curlResult); + ->andReturn($IHTTPResult); $this->dice->shouldReceive('create') ->with(IHTTPRequest::class) @@ -344,14 +344,14 @@ class InstallerTest extends MockedTest $this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; }); // Mocking the failed CURL Response - $curlResultF = \Mockery::mock(CurlResult::class); - $curlResultF + $IHTTPResultF = \Mockery::mock(IHTTPResult::class); + $IHTTPResultF ->shouldReceive('getReturnCode') ->andReturn('404'); // Mocking the working CURL Response - $curlResultW = \Mockery::mock(CurlResult::class); - $curlResultW + $IHTTPResultW = \Mockery::mock(IHTTPResult::class); + $IHTTPResultW ->shouldReceive('getReturnCode') ->andReturn('204'); @@ -360,11 +360,11 @@ class InstallerTest extends MockedTest $networkMock ->shouldReceive('fetchFull') ->with('https://test/install/testrewrite') - ->andReturn($curlResultF); + ->andReturn($IHTTPResultF); $networkMock ->shouldReceive('fetchFull') ->with('http://test/install/testrewrite') - ->andReturn($curlResultW); + ->andReturn($IHTTPResultW); $this->dice->shouldReceive('create') ->with(IHTTPRequest::class)