Restructure HTTPClient for new paradigm

This commit is contained in:
Philipp 2021-10-23 12:50:31 +02:00
parent fa55928ea3
commit 409d909d0f
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
25 changed files with 210 additions and 198 deletions

View file

@ -25,8 +25,8 @@ namespace Friendica\Core;
use Dice\Dice;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\DI;
use Friendica\Network\IHTTPResult;
use Friendica\Network\IHTTPClient;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
use Friendica\Network\HTTPClient\Capability\ICanRequestPerHttp;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\VFSTrait;
use Mockery;
@ -319,7 +319,7 @@ class InstallerTest extends MockedTest
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
// Mocking the CURL Response
$IHTTPResult = Mockery::mock(IHTTPResult::class);
$IHTTPResult = Mockery::mock(ICanHandleHttpResponses::class);
$IHTTPResult
->shouldReceive('getReturnCode')
->andReturn('404');
@ -331,7 +331,7 @@ class InstallerTest extends MockedTest
->andReturn('test Error');
// Mocking the CURL Request
$networkMock = Mockery::mock(IHTTPClient::class);
$networkMock = Mockery::mock(ICanRequestPerHttp::class);
$networkMock
->shouldReceive('fetchFull')
->with('https://test/install/testrewrite')
@ -342,7 +342,7 @@ class InstallerTest extends MockedTest
->andReturn($IHTTPResult);
$this->dice->shouldReceive('create')
->with(IHTTPClient::class)
->with(ICanRequestPerHttp::class)
->andReturn($networkMock);
DI::init($this->dice);
@ -366,19 +366,19 @@ class InstallerTest extends MockedTest
$this->l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
// Mocking the failed CURL Response
$IHTTPResultF = Mockery::mock(IHTTPResult::class);
$IHTTPResultF = Mockery::mock(ICanHandleHttpResponses::class);
$IHTTPResultF
->shouldReceive('getReturnCode')
->andReturn('404');
// Mocking the working CURL Response
$IHTTPResultW = Mockery::mock(IHTTPResult::class);
$IHTTPResultW = Mockery::mock(ICanHandleHttpResponses::class);
$IHTTPResultW
->shouldReceive('getReturnCode')
->andReturn('204');
// Mocking the CURL Request
$networkMock = Mockery::mock(IHTTPClient::class);
$networkMock = Mockery::mock(ICanRequestPerHttp::class);
$networkMock
->shouldReceive('fetchFull')
->with('https://test/install/testrewrite')
@ -389,7 +389,7 @@ class InstallerTest extends MockedTest
->andReturn($IHTTPResultW);
$this->dice->shouldReceive('create')
->with(IHTTPClient::class)
->with(ICanRequestPerHttp::class)
->andReturn($networkMock);
DI::init($this->dice);

View file

@ -40,7 +40,7 @@ use Friendica\DI;
use Friendica\Core\Config\Factory\Config;
use Friendica\Core\Config\Repository;
use Friendica\Core\Storage\Type;
use Friendica\Network\HTTPClient;
use Friendica\Network\HTTPClient\Client\HttpClientCan;
use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
@ -61,7 +61,7 @@ class StorageManagerTest extends DatabaseTest
private $logger;
/** @var L10n */
private $l10n;
/** @var HTTPClient */
/** @var HttpClientCan */
private $httpRequest;
protected function setUp(): void
@ -93,7 +93,7 @@ class StorageManagerTest extends DatabaseTest
$this->l10n = \Mockery::mock(L10n::class);
$this->httpRequest = \Mockery::mock(HTTPClient::class);
$this->httpRequest = \Mockery::mock(HttpClientCan::class);
}
protected function tearDown(): void

View file

@ -1,6 +1,6 @@
<?php
namespace Friendica\Test\src\Network;
namespace Friendica\Test\src\Network\HTTPClient\Client;
use Friendica\DI;
use Friendica\Test\DiceHttpMockHandlerTrait;

View file

@ -19,11 +19,11 @@
*
*/
namespace Friendica\Test\src\Network;
namespace Friendica\Test\src\Network\HTTPClient\Response;
use Dice\Dice;
use Friendica\DI;
use Friendica\Network\CurlResult;
use Friendica\Network\HTTPClient\Response\CurlResult;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@ -37,7 +37,7 @@ class CurlResultTest extends TestCase
/** @var Dice|MockInterface $dice */
$dice = \Mockery::mock(Dice::class)->makePartial();
$dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
$dice = $dice->addRules(include __DIR__ . '/../../../../../static/dependencies.config.php');
$logger = new NullLogger();
$dice->shouldReceive('create')
@ -52,12 +52,12 @@ class CurlResultTest extends TestCase
*/
public function testNormal()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
$headerArray = include(__DIR__ . '/../../datasets/curl/about.head.php');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head');
$headerArray = include(__DIR__ . '/../../../../datasets/curl/about.head.php');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local', $header . $body, [
$curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local', $header . $body, [
'http_code' => 200,
'content_type' => 'text/html; charset=utf-8',
'url' => 'https://test.local'
@ -80,12 +80,12 @@ class CurlResultTest extends TestCase
*/
public function testRedirect()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
$headerArray = include(__DIR__ . '/../../datasets/curl/about.head.php');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head');
$headerArray = include(__DIR__ . '/../../../../datasets/curl/about.head.php');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
$curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local/test/it', $header . $body, [
'http_code' => 301,
'content_type' => 'text/html; charset=utf-8',
'url' => 'https://test.local/test/it',
@ -107,12 +107,12 @@ class CurlResultTest extends TestCase
*/
public function testTimeout()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
$headerArray = include(__DIR__ . '/../../datasets/curl/about.head.php');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head');
$headerArray = include(__DIR__ . '/../../../../datasets/curl/about.head.php');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local/test/it', $header . $body, [
$curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local/test/it', $header . $body, [
'http_code' => 500,
'content_type' => 'text/html; charset=utf-8',
'url' => 'https://test.local/test/it',
@ -136,9 +136,9 @@ class CurlResultTest extends TestCase
*/
public function testRedirectHeader()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.redirect');
$headerArray = include(__DIR__ . '/../../datasets/curl/about.redirect.php');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.redirect');
$headerArray = include(__DIR__ . '/../../../../datasets/curl/about.redirect.php');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local/test/it?key=value', $header . $body, [
@ -162,10 +162,10 @@ class CurlResultTest extends TestCase
*/
public function testInHeader()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local', $header . $body, [
$curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local', $header . $body, [
'http_code' => 200,
'content_type' => 'text/html; charset=utf-8',
'url' => 'https://test.local'
@ -179,10 +179,10 @@ class CurlResultTest extends TestCase
*/
public function testGetHeaderArray()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local', $header . $body, [
$curlResult = new \Friendica\Network\HTTPClient\Response\CurlResult('https://test.local', $header . $body, [
'http_code' => 200,
'content_type' => 'text/html; charset=utf-8',
'url' => 'https://test.local'
@ -199,8 +199,8 @@ class CurlResultTest extends TestCase
*/
public function testGetHeaderWithParam()
{
$header = file_get_contents(__DIR__ . '/../../datasets/curl/about.head');
$body = file_get_contents(__DIR__ . '/../../datasets/curl/about.body');
$header = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.head');
$body = file_get_contents(__DIR__ . '/../../../../datasets/curl/about.body');
$curlResult = new CurlResult('https://test.local', $header . $body, [
'http_code' => 200,