Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK committed Oct 8, 2019
2 parents 42fa527 + 2ffd261 commit a5fbb74
Show file tree
Hide file tree
Showing 16 changed files with 1,004 additions and 153 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
---------

## 1.0.0 (2019-10-08)
- Initial release
- Refactoring of testing strategy
- Improve code coverage to ensure stability and sustainability

## 0.0.1-alpha (2019-09-27)
- Alpha release
- Allow GET, POST, PUT, PATCH & DELETE operation on the TrustedShops API
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -9,7 +9,9 @@ Requires PHP 7.0+. Abstraction is for chimps.

[![Build Status](https://travis-ci.org/antistatique/trustedshops-php-sdk.svg?branch=master)](https://travis-ci.org/antistatique/trustedshops-php-sdk)
[![StyleCI](https://github.styleci.io/repos/207270598/shield?branch=master)](https://github.styleci.io/repos/207270598)
[![Coverage Status](https://coveralls.io/repos/github/antistatique/trustedshops-php-sdk/badge.svg?branch=master)](https://coveralls.io/github/antistatique/trustedshops-php-sdk?branch=master)
[![Packagist](https://img.shields.io/packagist/dt/antistatique/trustedshops-php-sdk.svg?maxAge=2592000)](https://packagist.org/packages/antistatique/trustedshops-php-sdk)
[![License](https://poser.pugx.org/antistatique/trustedshops-php-sdk/license)](https://packagist.org/packages/antistatique/trustedshops-php-sdk)

Getting started
------------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.0.1-alpha
1.0.0
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -15,7 +15,8 @@
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^4.0",
"sensiolabs/security-checker": "^5.0",
"php-coveralls/php-coveralls": "^2.1"
"php-coveralls/php-coveralls": "^2.1",
"php-mock/php-mock-phpunit": "^2.4"
},
"autoload": {
"psr-4": {
Expand Down
170 changes: 169 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 15 additions & 17 deletions src/TrustedShops.php
Expand Up @@ -364,7 +364,7 @@ public function put($method, $args = array(), $timeout = self::TIMEOUT)
*
* @throws \Exception
*/
private function makeRequest($http_verb, $method, $args = array(), $timeout = self::TIMEOUT)
protected function makeRequest($http_verb, $method, $args = array(), $timeout = self::TIMEOUT)
{
$url = $this->api_endpoint . '/' . $method;

Expand Down Expand Up @@ -429,9 +429,9 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = se
break;
}

$responseContent = curl_exec($curl);
$response_content = curl_exec($curl);
$response['headers'] = curl_getinfo($curl);
$response = $this->setResponseState($response, $responseContent, $curl);
$response = $this->setResponseState($response, $response_content, $curl);
$formattedResponse = $this->formatResponse($response);

curl_close($curl);
Expand All @@ -452,7 +452,7 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = se
*
* @return array
*/
private function prepareStateForRequest($http_verb, $method, $url, $timeout)
protected function prepareStateForRequest($http_verb, $method, $url, $timeout)
{
$this->last_error = '';

Expand Down Expand Up @@ -484,11 +484,11 @@ private function prepareStateForRequest($http_verb, $method, $url, $timeout)
* @return array
* The parsed headers.
*/
private function getHeadersAsArray($headersAsString)
protected function getHeadersAsArray($headersAsString)
{
$headers = array();

foreach (explode("\r\n", $headersAsString) as $i => $line) {
foreach (explode(PHP_EOL, $headersAsString) as $i => $line) {
if (preg_match('/HTTP\/[1-2]/', substr($line, 0, 7)) === 1) { // http code
continue;
}
Expand All @@ -513,7 +513,7 @@ private function getHeadersAsArray($headersAsString)
* @param array $data
* Assoc array of data to attach.
*/
private function attachRequestPayload(&$curl, $data)
protected function attachRequestPayload(&$curl, $data)
{
$encoded = json_encode($data);
$this->last_request['body'] = $encoded;
Expand All @@ -529,7 +529,7 @@ private function attachRequestPayload(&$curl, $data)
* @return array|FALSE
* A decoded array from JSON response.
*/
private function formatResponse($response)
protected function formatResponse($response)
{
$this->last_response = $response;

Expand All @@ -547,7 +547,7 @@ private function formatResponse($response)
*
* @param array $response
* The response from the curl request.
* @param string $responseContent
* @param string $response_content
* The body of the response from the curl request.
* @param resource $curl
* The curl resource.
Expand All @@ -557,18 +557,16 @@ private function formatResponse($response)
*
* @throws \Exception
*/
private function setResponseState($response, $responseContent, $curl)
protected function setResponseState($response, $response_content, $curl)
{
if ($responseContent === FALSE) {
if ($response_content === FALSE) {
$this->last_error = curl_error($curl);
throw new Exception($this->last_error);
} else {

$headerSize = $response['headers']['header_size'];

$response['httpHeaders'] = $this->getHeadersAsArray(substr($responseContent, 0, $headerSize));
$response['body'] = substr($responseContent, $headerSize);

$response['httpHeaders'] = $this->getHeadersAsArray(substr($response_content, 0, $headerSize));
$response['body'] = substr($response_content, $headerSize);

if (isset($response['headers']['request_header'])) {
$this->last_request['headers'] = $response['headers']['request_header'];
Expand All @@ -593,7 +591,7 @@ private function setResponseState($response, $responseContent, $curl)
*
* @throws \Exception
*/
private function determineSuccess($response, $formattedResponse, $timeout)
protected function determineSuccess($response, $formattedResponse, $timeout)
{
$status = $this->findHTTPStatus($response, $formattedResponse);

Expand Down Expand Up @@ -627,7 +625,7 @@ private function determineSuccess($response, $formattedResponse, $timeout)
* @return int
* HTTP status code
*/
private function findHTTPStatus($response, $formattedResponse)
protected function findHTTPStatus($response, $formattedResponse)
{
if (!empty($response['headers']) && isset($response['headers']['http_code'])) {
return (int)$response['headers']['http_code'];
Expand Down
@@ -1,16 +1,14 @@
<?php

namespace Antistatique\TrustedShops\Tests;
namespace Antistatique\TrustedShops\Tests\Advanced;

use Antistatique\TrustedShops\TrustedShops;
use PHPUnit\Framework\TestCase;
use Antistatique\TrustedShops\Tests\RequestTestBase;
use Exception;
use RuntimeException;

/**
* @coversDefaultClass Antistatique\TrustedShops\TrustedShops
*/
class AdvancedRequestTest extends RequestTestBase
class QualityComplaintsTest extends RequestTestBase
{

/**
Expand All @@ -26,16 +24,6 @@ public function setup() {
$this->assertNotEmpty($TRUSTEDSHOPS_PASS, 'No environment variables! Copy .env.example -> .env and fill out your TrustedShops account details.');
}

/**
* @covers ::__construct
*/
public function testUnsupportedScoop()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Unsupported TrustedShops scoop "foo".');
new TrustedShops('foo');
}

/**
* @covers ::setApiCredentials
* @covers ::determineSuccess
Expand Down

0 comments on commit a5fbb74

Please sign in to comment.