diff --git a/.gitignore b/.gitignore index 7b8aee3..bc89a41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.phpunit.result.cache build/ composer.phar composer.lock diff --git a/.travis.yml b/.travis.yml index 0a76705..59d27a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/composer.json b/composer.json index 656a892..7ac1436 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -32,4 +31,4 @@ "ValueFrame\\Rest\\Tests\\": "tests/" } } -} \ No newline at end of file +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 627c7cd..56cc256 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,11 +2,10 @@ @@ -16,7 +15,7 @@ - + ./tests/ diff --git a/src/Client.php b/src/Client.php index 1fe933d..e808e89 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,14 +3,19 @@ /** * /src/Client.php * - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ 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 @@ -29,7 +34,7 @@ * @method Promise\PromiseInterface deleteAsync(string|UriInterface $uri, array $options = []) * * @package ValueFrame\Rest - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ class Client { @@ -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]; @@ -172,7 +177,7 @@ 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 ?? []); } /** @@ -180,14 +185,14 @@ public function getOptions(array $options = null): 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, ], ]; diff --git a/src/Factory.php b/src/Factory.php index 185985a..08e773d 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -3,7 +3,7 @@ /** * /src/Factory.php * - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ namespace ValueFrame\Rest; @@ -11,7 +11,7 @@ * Class Factory * * @package ValueFrame\Rest - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ class Factory { @@ -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; } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 18cf9ca..3ebf037 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -3,7 +3,7 @@ /** * /tests/ClientTest.php * - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ namespace ValueFrame\Rest\Tests; @@ -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'); @@ -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']; @@ -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'); } diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index 417185c..29b29eb 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -3,7 +3,7 @@ /** * /tests/FactoryTest.php * - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ namespace ValueFrame\Rest\Tests; @@ -17,7 +17,7 @@ */ class FactoryTest extends TestCase { - public function testThatClientHasBeenCreatedWithCorrectParameters() + public function testThatClientHasBeenCreatedWithCorrectParameters(): void { $client = Factory::build('customer', 'token', 'resource'); @@ -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'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 531f2ca..7b6548a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,7 +3,7 @@ /** * /tests/bootstrap.php * - * @author TLe, Tarmo Leppänen + * @author TLe, Tarmo Leppänen */ // TODO: add necessary bootstrap for tests.