Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency update #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.phpunit.result.cache
build/
composer.phar
composer.lock
Expand Down
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ matrix:
- php: master
- php: nightly
include:
- php: 7.0
- php: 7.2
env:
- USE_XDEBUG=false
- 'HIGHEST_LOWEST="update --prefer-lowest"'
- php: 7.1
- php: 7.3
env:
- USE_XDEBUG=false
- php: 7.2
env:
- USE_XDEBUG=false
- php: 7.2
- php: 7.3
env:
- COVERAGE=true

Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.0",
"php": ">=7.2 | >=8.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3"
"guzzlehttp/guzzle": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^6.5 | ^7.4",
"squizlabs/php_codesniffer": "^3.2",
"codedungeon/phpunit-result-printer": "^0.5 | ^0.23",
"phpmetrics/phpmetrics": "^2.3"
"phpunit/phpunit": "^8.5 | ^9.5",
"squizlabs/php_codesniffer": "^3.6",
"phpmetrics/phpmetrics": "^2.7"
},
"autoload": {
"psr-4": {
Expand All @@ -32,4 +31,4 @@
"ValueFrame\\Rest\\Tests\\": "tests/"
}
}
}
}
5 changes: 2 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.4/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"
>
<php>
<ini name="error_reporting" value="-1" />
Expand All @@ -16,7 +15,7 @@
</php>

<testsuites>
<testsuite>
<testsuite name="tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
21 changes: 13 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
/**
* /src/Client.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
namespace ValueFrame\Rest;

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Promise;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use function array_merge_recursive;
use function md5;
use function time;
use function trim;

/**
* Class Client
Expand All @@ -29,7 +34,7 @@
* @method Promise\PromiseInterface deleteAsync(string|UriInterface $uri, array $options = [])
*
* @package ValueFrame\Rest
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
class Client
{
Expand Down Expand Up @@ -59,12 +64,12 @@ class Client
*
* @return \GuzzleHttp\Promise\PromiseInterface|mixed|ResponseInterface
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException|\GuzzleHttp\Exception\GuzzleException
*/
public function __call(string $method, array $args)
{
if (count($args) < 1) {
throw new \InvalidArgumentException('Magic request methods require a URI and optional options array');
throw new InvalidArgumentException('Magic request methods require a URI and optional options array');
}

$uri = $args[0];
Expand Down Expand Up @@ -172,22 +177,22 @@ public function getClient(): GuzzleClient
*/
public function getOptions(array $options = null): array
{
return \array_merge_recursive($this->getHeaders(), $options ?? []);
return array_merge_recursive($this->getHeaders(), $options ?? []);
}

/**
* @return array
*/
private function getHeaders(): array
{
$timestamp = \time();
$resource = \trim($this->getResource(), '/');
$timestamp = time();
$resource = trim($this->getResource(), '/');

return [
'headers' => [
'X-VF-REST-USER' => $this->getCustomer(),
'X-VF-REST-TIMESTAMP' => $timestamp,
'X-VF-REST-HASH' => \md5($timestamp . '/' . $resource . '/' . $this->getToken()),
'X-VF-REST-HASH' => md5($timestamp . '/' . $resource . '/' . $this->getToken()),
'X-VF-REST-REAL-JSON-OUTPUT' => true,
],
];
Expand Down
8 changes: 3 additions & 5 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
/**
* /src/Factory.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
namespace ValueFrame\Rest;

/**
* Class Factory
*
* @package ValueFrame\Rest
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
class Factory
{
Expand All @@ -27,12 +27,10 @@ class Factory
*/
public static function build(string $customer, string $token, string $resource, string $baseUri = null): Client
{
$client = (new Client())
return (new Client())
->setCustomer($customer)
->setToken($token)
->setResource($resource)
->setBaseUri($baseUri);

return $client;
}
}
8 changes: 4 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* /tests/ClientTest.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
namespace ValueFrame\Rest\Tests;

Expand All @@ -24,7 +24,7 @@ class ClientTest extends TestCase
*/
private $client;

public function testThatGetClientUsesExpectedBaseUri()
public function testThatGetClientUsesExpectedBaseUri(): void
{
/** @var Uri $baseUri */
$baseUri = $this->client->getClient()->getConfig('base_uri');
Expand All @@ -34,7 +34,7 @@ public function testThatGetClientUsesExpectedBaseUri()
static::assertSame('/rest/v2/resource', $baseUri->getPath());
}

public function testThatGetOptionsAddsExpectedHeaders()
public function testThatGetOptionsAddsExpectedHeaders(): void
{
$options = $this->client->getOptions()['headers'];

Expand All @@ -43,7 +43,7 @@ public function testThatGetOptionsAddsExpectedHeaders()
static::assertArrayHasKey('X-VF-REST-HASH', $options);
}

protected function setUp()
protected function setUp(): void
{
$this->client = Factory::build('customer', 'token', 'resource');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* /tests/FactoryTest.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
namespace ValueFrame\Rest\Tests;

Expand All @@ -17,7 +17,7 @@
*/
class FactoryTest extends TestCase
{
public function testThatClientHasBeenCreatedWithCorrectParameters()
public function testThatClientHasBeenCreatedWithCorrectParameters(): void
{
$client = Factory::build('customer', 'token', 'resource');

Expand All @@ -26,14 +26,14 @@ public function testThatClientHasBeenCreatedWithCorrectParameters()
static::assertSame('resource', $client->getResource());
}

public function testThatClientHasDefaultBaseUri()
public function testThatClientHasDefaultBaseUri(): void
{
$client = Factory::build('customer', 'token', 'resource');

static::assertSame('https://rest.valueframe.com/rest/v2/', $client->getBaseUri());
}

public function testThatClientHasCustomBaseUri()
public function testThatClientHasCustomBaseUri(): void
{
$client = Factory::build('customer', 'token', 'resource', 'custom');

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* /tests/bootstrap.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/

// TODO: add necessary bootstrap for tests.