Replace IHTTPResult for CurlResult usages
This commit is contained in:
parent
7009d90add
commit
05ecd1e3d4
4 changed files with 29 additions and 28 deletions
|
@ -32,7 +32,7 @@ use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Module\Register;
|
use Friendica\Module\Register;
|
||||||
use Friendica\Network\CurlResult;
|
use Friendica\Network\IHTTPResult;
|
||||||
use Friendica\Protocol\Relay;
|
use Friendica\Protocol\Relay;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
@ -672,17 +672,18 @@ class GServer
|
||||||
* Detect server type by using the nodeinfo data
|
* Detect server type by using the nodeinfo data
|
||||||
*
|
*
|
||||||
* @param string $url address of the server
|
* @param string $url address of the server
|
||||||
* @param CurlResult $curlResult
|
* @param IHTTPResult $httpResult
|
||||||
|
*
|
||||||
* @return array Server data
|
* @return array Server data
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @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 [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$nodeinfo = json_decode($curlResult->getBody(), true);
|
$nodeinfo = json_decode($httpResult->getBody(), true);
|
||||||
|
|
||||||
if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
|
if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -101,7 +101,7 @@ class CurlResult implements IHTTPResult
|
||||||
*
|
*
|
||||||
* @param string $url optional URL
|
* @param string $url optional URL
|
||||||
*
|
*
|
||||||
* @return CurlResult a CURL with error response
|
* @return IHTTPResult a CURL with error response
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function createErrorCurl($url = '')
|
public static function createErrorCurl($url = '')
|
||||||
|
|
|
@ -52,7 +52,7 @@ interface IHTTPRequest
|
||||||
* @param string $accept_content supply Accept: header with 'accept_content' as the value
|
* @param string $accept_content supply Accept: header with 'accept_content' as the value
|
||||||
* @param string $cookiejar Path to cookie jar file
|
* @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, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
|
public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ interface IHTTPRequest
|
||||||
* 'cookiejar' => path to cookie jar file
|
* 'cookiejar' => path to cookie jar file
|
||||||
* 'header' => header array
|
* 'header' => header array
|
||||||
*
|
*
|
||||||
* @return CurlResult
|
* @return IHTTPResult
|
||||||
*/
|
*/
|
||||||
public function get(string $url, array $opts = []);
|
public function get(string $url, array $opts = []);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ interface IHTTPRequest
|
||||||
* @param array $headers HTTP headers
|
* @param array $headers HTTP headers
|
||||||
* @param int $timeout The timeout in seconds, default system config value or 60 seconds
|
* @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);
|
public function post(string $url, $params, array $headers = [], int $timeout = 0);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Friendica\Core;
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\CurlResult;
|
use Friendica\Network\IHTTPResult;
|
||||||
use Friendica\Network\IHTTPRequest;
|
use Friendica\Network\IHTTPRequest;
|
||||||
use Friendica\Test\MockedTest;
|
use Friendica\Test\MockedTest;
|
||||||
use Friendica\Test\Util\VFSTrait;
|
use Friendica\Test\Util\VFSTrait;
|
||||||
|
@ -319,14 +319,14 @@ class InstallerTest extends MockedTest
|
||||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||||
|
|
||||||
// Mocking the CURL Response
|
// Mocking the CURL Response
|
||||||
$curlResult = Mockery::mock(CurlResult::class);
|
$IHTTPResult = Mockery::mock(IHTTPResult::class);
|
||||||
$curlResult
|
$IHTTPResult
|
||||||
->shouldReceive('getReturnCode')
|
->shouldReceive('getReturnCode')
|
||||||
->andReturn('404');
|
->andReturn('404');
|
||||||
$curlResult
|
$IHTTPResult
|
||||||
->shouldReceive('getRedirectUrl')
|
->shouldReceive('getRedirectUrl')
|
||||||
->andReturn('');
|
->andReturn('');
|
||||||
$curlResult
|
$IHTTPResult
|
||||||
->shouldReceive('getError')
|
->shouldReceive('getError')
|
||||||
->andReturn('test Error');
|
->andReturn('test Error');
|
||||||
|
|
||||||
|
@ -335,11 +335,11 @@ class InstallerTest extends MockedTest
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('fetchFull')
|
||||||
->with('https://test/install/testrewrite')
|
->with('https://test/install/testrewrite')
|
||||||
->andReturn($curlResult);
|
->andReturn($IHTTPResult);
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('fetchFull')
|
||||||
->with('http://test/install/testrewrite')
|
->with('http://test/install/testrewrite')
|
||||||
->andReturn($curlResult);
|
->andReturn($IHTTPResult);
|
||||||
|
|
||||||
$this->dice->shouldReceive('create')
|
$this->dice->shouldReceive('create')
|
||||||
->with(IHTTPRequest::class)
|
->with(IHTTPRequest::class)
|
||||||
|
@ -366,14 +366,14 @@ class InstallerTest extends MockedTest
|
||||||
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
|
||||||
|
|
||||||
// Mocking the failed CURL Response
|
// Mocking the failed CURL Response
|
||||||
$curlResultF = Mockery::mock(CurlResult::class);
|
$IHTTPResultF = Mockery::mock(IHTTPResult::class);
|
||||||
$curlResultF
|
$IHTTPResultF
|
||||||
->shouldReceive('getReturnCode')
|
->shouldReceive('getReturnCode')
|
||||||
->andReturn('404');
|
->andReturn('404');
|
||||||
|
|
||||||
// Mocking the working CURL Response
|
// Mocking the working CURL Response
|
||||||
$curlResultW = Mockery::mock(CurlResult::class);
|
$IHTTPResultW = Mockery::mock(IHTTPResult::class);
|
||||||
$curlResultW
|
$IHTTPResultW
|
||||||
->shouldReceive('getReturnCode')
|
->shouldReceive('getReturnCode')
|
||||||
->andReturn('204');
|
->andReturn('204');
|
||||||
|
|
||||||
|
@ -382,11 +382,11 @@ class InstallerTest extends MockedTest
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('fetchFull')
|
||||||
->with('https://test/install/testrewrite')
|
->with('https://test/install/testrewrite')
|
||||||
->andReturn($curlResultF);
|
->andReturn($IHTTPResultF);
|
||||||
$networkMock
|
$networkMock
|
||||||
->shouldReceive('fetchFull')
|
->shouldReceive('fetchFull')
|
||||||
->with('http://test/install/testrewrite')
|
->with('http://test/install/testrewrite')
|
||||||
->andReturn($curlResultW);
|
->andReturn($IHTTPResultW);
|
||||||
|
|
||||||
$this->dice->shouldReceive('create')
|
$this->dice->shouldReceive('create')
|
||||||
->with(IHTTPRequest::class)
|
->with(IHTTPRequest::class)
|
||||||
|
|
Loading…
Reference in a new issue