Skip to content

Commit

Permalink
Version 3.0 (#6)
Browse files Browse the repository at this point in the history
Version 3.0
  • Loading branch information
RomulusED69 authored Jan 6, 2020
2 parents 1565f97 + 7afb971 commit 3263f7a
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 283 deletions.
14 changes: 0 additions & 14 deletions .coke

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
composer.lock
bin/*
!bin/.gitkeep
.php_cs.cache
28 changes: 28 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => [
'align_double_arrow' => true,
'align_equals' => true
],
'no_unreachable_default_argument_value' => false,
'braces' => [
'allow_single_line_closure' => true,
],
'heredoc_to_nowdoc' => false,
'phpdoc_summary' => false,
'declare_strict_types' => true,
])
->setFinder($finder)
;
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ before_script:
- composer install --no-interaction --prefer-dist

script:
- bin/php-cs-fixer fix --verbose --diff --dry-run src/
- bin/phpspec run -n
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.1",
"php-http/message-factory": "^1.0.2",
"php-http/httplug": "^1.0",
"php-http/httplug": "^2.0",
"php-http/discovery": "^1.0",
"psr/cache": "^1.0",
"symfony/cache": "^3.3|^4.0"
"symfony/cache": "^4.0|^5.0"
},
"require-dev": {
"phpspec/phpspec": "^3.2",
"phpspec/phpspec": "^6.0",
"php-http/message": "^1.0",
"php-http/guzzle6-adapter": "^1.0",
"m6web/symfony2-coding-standard": "^3.3.0",
"m6web/coke": "^2.1"
"php-http/guzzle6-adapter": "^2.0",
"friendsofphp/php-cs-fixer": "^2.16"
},
"config": {
"bin-dir": "bin"
Expand Down
69 changes: 35 additions & 34 deletions spec/Client/ClientSpec.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<?php

declare(strict_types=1);

namespace spec\Yproximite\Ekomi\Api\Client;

use Http\Client\Exception\HttpException;
use Http\Client\HttpClient;
use PhpSpec\ObjectBehavior;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\MessageFactory;
use PhpSpec\ObjectBehavior;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Http\Client\Exception\HttpException;
use Http\Discovery\MessageFactoryDiscovery;

use Psr\Http\Message\StreamInterface;
use Yproximite\Ekomi\Api\Client\Client;
use Yproximite\Ekomi\Api\Exception\TransferException;
use Yproximite\Ekomi\Api\Exception\AuthenficationException;
use Yproximite\Ekomi\Api\Exception\InvalidResponseException;
use Yproximite\Ekomi\Api\Exception\TransferException;

class ClientSpec extends ObjectBehavior
{
const BASE_URL = 'http://api.host';

function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType(Client::class);
}

function let(
public function let(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $tokenRequest,
Expand All @@ -39,7 +40,7 @@ function let(
$tokenRequestUri = sprintf('%s/security/login', self::BASE_URL);
$tokenRawRequest = json_encode(['username' => 'abcd', 'password' => 'xxxx']);
$tokenRawResponse = json_encode(['access_token' => 'efgh']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('POST', $tokenRequestUri, $tokenHeaders, $tokenRawRequest)->willReturn($tokenRequest);
$httpClient->sendRequest($tokenRequest)->willReturn($tokenResponse);
Expand All @@ -58,7 +59,7 @@ function let(
);
}

function it_should_send_get_request(
public function it_should_send_get_request(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $request,
Expand All @@ -71,7 +72,7 @@ function it_should_send_get_request(
$rawQuery = http_build_query(['query' => 'test']);
$requestUri = sprintf('%s/example?%s', self::BASE_URL, $rawQuery);
$rawResponse = json_encode(['foo' => 'bar']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('GET', $requestUri, $headers, null)->willReturn($request);
$httpClient->sendRequest($request)->willReturn($response);
Expand All @@ -89,7 +90,7 @@ function it_should_send_get_request(
$this->sendRequest('GET', 'example', ['query' => 'test']);
}

function it_should_send_post_request(
public function it_should_send_post_request(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $request,
Expand All @@ -102,7 +103,7 @@ function it_should_send_post_request(
$requestUri = sprintf('%s/example', self::BASE_URL);
$rawRequest = json_encode(['query' => 'test']);
$rawResponse = json_encode(['foo' => 'bar']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('POST', $requestUri, $headers, $rawRequest)->willReturn($request);
$httpClient->sendRequest($request)->willReturn($response);
Expand All @@ -120,7 +121,7 @@ function it_should_send_post_request(
$this->sendRequest('POST', 'example', ['query' => 'test']);
}

function it_should_ask_for_api_token_once(
public function it_should_ask_for_api_token_once(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $firstRequest,
Expand All @@ -137,7 +138,7 @@ function it_should_ask_for_api_token_once(
$firstHeaders = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$firstRequestUri = sprintf('%s/first', self::BASE_URL);
$firstRawResponse = json_encode(['foo' => 'bar']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('GET', $firstRequestUri, $firstHeaders, null)->willReturn($firstRequest);
$httpClient->sendRequest($firstRequest)->willReturn($firstResponse);
Expand All @@ -159,7 +160,7 @@ function it_should_ask_for_api_token_once(
$secondHeaders = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$secondRequestUri = sprintf('%s/second', self::BASE_URL);
$secondRawResponse = json_encode(['foo' => 'bar']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('GET', $secondRequestUri, $secondHeaders, null)->willReturn($secondRequest);
$httpClient->sendRequest($secondRequest)->willReturn($secondResponse);
Expand All @@ -178,7 +179,7 @@ function it_should_ask_for_api_token_once(
$httpClient->sendRequest($tokenRequest)->shouldHaveBeenCalledTimes(1);
}

function it_should_renew_the_token_and_resend_the_request(
public function it_should_renew_the_token_and_resend_the_request(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $firstRequest,
Expand All @@ -194,7 +195,7 @@ function it_should_renew_the_token_and_resend_the_request(
$firstHeaders = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$firstRequestUri = sprintf('%s/first', self::BASE_URL);
$firstRawResponse = json_encode(['foo' => 'bar']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('GET', $firstRequestUri, $firstHeaders, null)->willReturn($firstRequest);
$httpClient->sendRequest($firstRequest)->willReturn($firstResponse);
Expand Down Expand Up @@ -226,9 +227,9 @@ function it_should_renew_the_token_and_resend_the_request(
$secondRequestCounter = 0;

$httpClient->sendRequest($secondRequest)->will(function () use ($secondRequestCounter, $secondResponse) {
$secondRequestCounter ++;
++$secondRequestCounter;

if ($secondRequestCounter === 1) {
if (1 === $secondRequestCounter) {
return MessageFactoryDiscovery::find()->createResponse(401);
}

Expand All @@ -240,7 +241,7 @@ function it_should_renew_the_token_and_resend_the_request(
$this->shouldThrow(InvalidResponseException::class)->during('sendRequest', ['GET', 'second']);
}

function it_should_not_renew_the_token(
public function it_should_not_renew_the_token(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $request,
Expand All @@ -253,7 +254,7 @@ function it_should_not_renew_the_token(
$headers = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$requestUri = sprintf('%s/example', self::BASE_URL);
$rawResponse = json_encode(['foo' => 'bar']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('GET', $requestUri, $headers, null)->willReturn($request);
$httpClient->sendRequest($request)->willReturn($response);
Expand All @@ -272,7 +273,7 @@ function it_should_not_renew_the_token(
$httpClient->sendRequest($tokenRequest)->shouldHaveBeenCalledTimes(1);
}

function it_should_throw_transfer_exception_on_http_exception(
public function it_should_throw_transfer_exception_on_http_exception(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $request,
Expand All @@ -281,7 +282,7 @@ function it_should_throw_transfer_exception_on_http_exception(
) {
$headers = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$requestUri = sprintf('%s/example', self::BASE_URL);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$errorResponse = MessageFactoryDiscovery::find()->createResponse(500);
$httpException = HttpException::create($request->getWrappedObject(), $errorResponse);
Expand All @@ -296,7 +297,7 @@ function it_should_throw_transfer_exception_on_http_exception(
$this->shouldThrow(TransferException::class)->during('sendRequest', ['GET', 'example']);
}

function it_should_throw_invalid_response_exception_on_bad_status_code(
public function it_should_throw_invalid_response_exception_on_bad_status_code(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $request,
Expand All @@ -306,7 +307,7 @@ function it_should_throw_invalid_response_exception_on_bad_status_code(
) {
$headers = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$requestUri = sprintf('%s/example', self::BASE_URL);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$messageFactory->createRequest('GET', $requestUri, $headers, null)->willReturn($request);
$httpClient->sendRequest($request)->willReturn($response);
Expand All @@ -319,7 +320,7 @@ function it_should_throw_invalid_response_exception_on_bad_status_code(
$this->shouldThrow(InvalidResponseException::class)->during('sendRequest', ['GET', 'example']);
}

function it_should_throw_invalid_response_exception_on_broken_response_body(
public function it_should_throw_invalid_response_exception_on_broken_response_body(
HttpClient $httpClient,
MessageFactory $messageFactory,
RequestInterface $request,
Expand All @@ -330,7 +331,7 @@ function it_should_throw_invalid_response_exception_on_broken_response_body(
) {
$headers = ['Content-Type' => 'application/json', 'Authorization' => 'ekomi efgh'];
$requestUri = sprintf('%s/example', self::BASE_URL);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$cacheItem->get()->willReturn(null);
$cache->getItem($cacheKey)->willReturn($cacheItem);
Expand All @@ -346,15 +347,15 @@ function it_should_throw_invalid_response_exception_on_broken_response_body(
$this->shouldThrow(InvalidResponseException::class)->during('sendRequest', ['GET', 'example']);
}

function it_should_throw_authenfication_exception_on_http_exception(
public function it_should_throw_authenfication_exception_on_http_exception(
HttpClient $httpClient,
RequestInterface $tokenRequest,
CacheItemPoolInterface $cache,
CacheItemInterface $cacheItem
) {
$errorResponse = MessageFactoryDiscovery::find()->createResponse(500);
$httpException = HttpException::create($tokenRequest->getWrappedObject(), $errorResponse);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$cacheItem->get()->willReturn(null);
$cache->getItem($cacheKey)->willReturn($cacheItem);
Expand All @@ -366,7 +367,7 @@ function it_should_throw_authenfication_exception_on_http_exception(
$this->shouldThrow(AuthenficationException::class)->during('sendRequest', ['GET', 'example']);
}

function it_should_throw_authenfication_exception_on_bad_status_code(
public function it_should_throw_authenfication_exception_on_bad_status_code(
ResponseInterface $tokenResponse,
CacheItemPoolInterface $cache,
CacheItemInterface $cacheItem
Expand All @@ -382,7 +383,7 @@ function it_should_throw_authenfication_exception_on_bad_status_code(
$this->shouldThrow(AuthenficationException::class)->during('sendRequest', ['GET', 'example']);
}

function it_should_throw_authenfication_exception_on_broken_response_body(
public function it_should_throw_authenfication_exception_on_broken_response_body(
StreamInterface $tokenStream,
CacheItemPoolInterface $cache,
CacheItemInterface $cacheItem
Expand All @@ -398,13 +399,13 @@ function it_should_throw_authenfication_exception_on_broken_response_body(
$this->shouldThrow(AuthenficationException::class)->during('sendRequest', ['GET', 'example']);
}

function it_should_throw_authenfication_exception_on_bad_response_body(
public function it_should_throw_authenfication_exception_on_bad_response_body(
StreamInterface $tokenStream,
CacheItemPoolInterface $cache,
CacheItemInterface $cacheItem
) {
$rawResponse = json_encode(['it' => 'is not a token']);
$cacheKey = 'xxxx';
$cacheKey = 'xxxx';

$tokenStream->__toString()->willReturn($rawResponse);
$cacheItem->get()->willReturn(null);
Expand Down
7 changes: 4 additions & 3 deletions spec/Message/Order/OrderListMessageSpec.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?php

declare(strict_types=1);

namespace spec\Yproximite\Ekomi\Api\Message\Order;

use PhpSpec\ObjectBehavior;

use Yproximite\Ekomi\Api\Message\Order\OrderListMessage;

class OrderListMessageSpec extends ObjectBehavior
{
function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType(OrderListMessage::class);
}

function it_should_build()
public function it_should_build()
{
$this->setOffset(5);
$this->setLimit(15);
Expand Down
Loading

0 comments on commit 3263f7a

Please sign in to comment.