Skip to content

Commit

Permalink
feature/Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdodonov committed Dec 3, 2020
1 parent 58b43a6 commit 6b560c3
Show file tree
Hide file tree
Showing 15 changed files with 599 additions and 336 deletions.
5 changes: 3 additions & 2 deletions ServiceClient.php → Mezon/Service/ServiceClient.php
Expand Up @@ -2,6 +2,7 @@
namespace Mezon\Service;

use Mezon\CustomClient\CustomClient;
use Mezon\DnsClient\DnsClient;

/**
* Class ServiceClient
Expand Down Expand Up @@ -64,9 +65,9 @@ class ServiceClient extends CustomClient
*/
public function __construct(string $service, string $login = '', string $password = '', array $headers = [])
{
if (\Mezon\DnsClient\DnsClient::serviceExists($service)) {
if (DnsClient::serviceExists($service)) {
$this->service = $service;
parent::__construct(\Mezon\DnsClient\DnsClient::resolveHost($service), $headers);
parent::__construct(DnsClient::resolveHost($service), $headers);
} elseif (strpos($service, 'http://') === false && strpos($service, 'https://') === false) {
throw (new \Exception('Service ' . $service . ' was not found in DNS'));
} else {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions Mezon/Service/Tests/ServiceClientUnitTest.php
@@ -0,0 +1,6 @@
<?php
namespace Mezon\Service\Tests;

class ServiceClientUnitTest extends ServiceClientUnitTests
{
}
@@ -1,58 +1,9 @@
<?php
namespace Mezon\Service\Tests;

/**
* Class ServiceClientUnitTests
*
* @package ServiceClient
* @subpackage ServiceClientUnitTests
* @author Dodonov A.A.
* @version v.1.0 (2019/09/20)
* @copyright Copyright (c) 2019, aeon.org
*/
class TestingServiceClient extends \Mezon\Service\ServiceClient
{

/**
* Method returns concrete url by it's locator
*
* @param string $urlLocator
* url locator
* @return string concrete URL
*/
public function getRequestUriPublic(string $urlLocator): string
{
return $this->getRequestUrl($urlLocator);
}

/**
* Result of the sendRequest method
*
* @var array
*/
public $sendRequestResult = [
'body',
1
];

/**
*
* @param string $url
* URL
* @param array $headers
* Headers
* @param string $method
* Request HTTP Method
* @param array $data
* Request data
* @return array Response body and HTTP code
* @codeCoverageIgnore
*/
protected function sendRequest(string $url, array $headers, string $method, array $data = []): array
{
return $this->sendRequestResult;
}
}
use PHPUnit\Framework\TestCase;
use Mezon\Service\ServiceClient;
use Mezon\DnsClient\DnsClient;

/**
* Basic tests for service client
Expand All @@ -61,21 +12,21 @@ protected function sendRequest(string $url, array $headers, string $method, arra
* @group baseTests
* @codeCoverageIgnore
*/
class ServiceClientUnitTests extends \PHPUnit\Framework\TestCase
class ServiceClientUnitTests extends TestCase
{

/**
* Client class name
*/
protected $clientClassName = \Mezon\Service\ServiceClient::class;
protected $clientClassName = ServiceClient::class;

/**
* Common setup for all tests
*/
public function setUp(): void
{
\Mezon\DnsClient\DnsClient::clear();
\Mezon\DnsClient\DnsClient::setService('existing-service', 'https://existing-service.com');
DnsClient::clear();
DnsClient::setService('existing-service', 'https://existing-service.com');
}

/**
Expand Down Expand Up @@ -415,7 +366,8 @@ public function testGetReuqetsUrlWithHandlingError(): void
/**
* Mtrhod tests case when sendRequest method have returned invalid json
*/
public function testInvalidJsonReturnedFromSendRequest():void{
public function testInvalidJsonReturnedFromSendRequest(): void
{
// setup and assertions
$this->expectException(\Mezon\Rest\Exception::class);
$client = new TestingServiceClient('https://some-service');
Expand Down
57 changes: 57 additions & 0 deletions Mezon/Service/Tests/TestingServiceClient.php
@@ -0,0 +1,57 @@
<?php
namespace Mezon\Service\Tests;

use Mezon\Service\ServiceClient;

/**
* Class ServiceClientUnitTests
*
* @package ServiceClient
* @subpackage ServiceClientUnitTests
* @author Dodonov A.A.
* @version v.1.0 (2019/09/20)
* @copyright Copyright (c) 2019, aeon.org
*/
class TestingServiceClient extends ServiceClient
{

/**
* Method returns concrete url by it's locator
*
* @param string $urlLocator
* url locator
* @return string concrete URL
*/
public function getRequestUriPublic(string $urlLocator): string
{
return $this->getRequestUrl($urlLocator);
}

/**
* Result of the sendRequest method
*
* @var array
*/
public $sendRequestResult = [
'body',
1
];

/**
*
* @param string $url
* URL
* @param array $headers
* Headers
* @param string $method
* Request HTTP Method
* @param array $data
* Request data
* @return array Response body and HTTP code
* @codeCoverageIgnore
*/
protected function sendRequest(string $url, array $headers, string $method, array $data = []): array
{
return $this->sendRequestResult;
}
}
5 changes: 0 additions & 5 deletions Tests/ServiceClientUnitTest.php

This file was deleted.

5 changes: 4 additions & 1 deletion composer.json
Expand Up @@ -10,6 +10,9 @@
"role": "Founder"
}
],
"require-dev": {
"phpunit/phpunit": "^8.5"
},
"require": {
"php": ">=7.2",
"mezon/custom-client" : "^1.0",
Expand All @@ -26,7 +29,7 @@
"prefer-stable": true,
"autoload": {
"psr-4": {
"Mezon\\Service\\": ""
"Mezon\\": "./Mezon/"
}
},
"scripts": {
Expand Down

0 comments on commit 6b560c3

Please sign in to comment.