diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index f6cc126..2d4fede 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -8,10 +8,10 @@ on:
jobs:
build:
- runs-on: ubuntu-20.04
+ runs-on: ubuntu-latest
strategy:
matrix:
- php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
+ php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
steps:
- name: Checkout
uses: actions/checkout@v2
diff --git a/composer.json b/composer.json
index 89ad081..53f0f92 100644
--- a/composer.json
+++ b/composer.json
@@ -14,12 +14,12 @@
"sort-packages": true
},
"require": {
- "php": "^7.0",
- "traderinteractive/util": "^3.0",
- "guzzlehttp/guzzle": "^6.3"
+ "php": "^7.0||^8.0",
+ "guzzlehttp/guzzle": "^6.3",
+ "traderinteractive/util-arrays": "^3.1||^4.0"
},
"require-dev": {
- "phpunit/phpunit": "^6.0",
+ "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"squizlabs/php_codesniffer": "^3.2"
},
"autoload": {
diff --git a/phpcs.xml b/phpcs.xml
index a93990e..a72f6d1 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -4,5 +4,5 @@
*/vendor/*
-
+
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index dc845da..ba76cec 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,4 +1,4 @@
-
+
./tests
diff --git a/src/Databases/AbstractNetAcuityDatabase.php b/src/Databases/AbstractNetAcuityDatabase.php
index 6185203..6f05cff 100644
--- a/src/Databases/AbstractNetAcuityDatabase.php
+++ b/src/Databases/AbstractNetAcuityDatabase.php
@@ -115,7 +115,7 @@ protected function parseBody(array $response)
*
* @return string The formatted url query string.
*/
- protected function buildQuery(string $userToken, string $ip) : string
+ protected function buildQuery(string $userToken, string $ip): string
{
$baseUrl = 'https://usa.cloud.netacuity.com/webservice/query';
return "{$baseUrl}?u={$userToken}&dbs={$this->databaseIdentifier}&ip={$ip}&json=true";
diff --git a/src/NetAcuity.php b/src/NetAcuity.php
index c26dc63..17dfe9a 100644
--- a/src/NetAcuity.php
+++ b/src/NetAcuity.php
@@ -3,7 +3,6 @@
namespace TraderInteractive\NetAcuity;
use TraderInteractive\NetAcuity\Databases\NetAcuityDatabaseInterface;
-use TraderInteractive\Util;
use Exception;
/**
@@ -59,9 +58,8 @@ public function __construct(NetAcuityDatabaseInterface $database)
* @type string $timezone-name
* }
*/
- public function getGeo(string $ip) : array
+ public function getGeo(string $ip): array
{
- Util::throwIfNotType(['string' => $ip], true);
return $this->database->fetch($ip);
}
}
diff --git a/src/NetAcuityInterface.php b/src/NetAcuityInterface.php
index e15f350..992e30f 100644
--- a/src/NetAcuityInterface.php
+++ b/src/NetAcuityInterface.php
@@ -39,5 +39,5 @@ interface NetAcuityInterface
* @type string $timezone-name
* }
*/
- public function getGeo(string $ip) : array;
+ public function getGeo(string $ip): array;
}
diff --git a/tests/Databases/AbstractNetAcuityDatabaseTest.php b/tests/Databases/AbstractNetAcuityDatabaseTest.php
index 1aedb0f..b2e6d78 100644
--- a/tests/Databases/AbstractNetAcuityDatabaseTest.php
+++ b/tests/Databases/AbstractNetAcuityDatabaseTest.php
@@ -151,12 +151,12 @@ public function getGeoWithExtraFieldEdge()
*
* @test
* @covers ::fetch
- * @expectedException Exception
- * @expectedExceptionMessage NetAcuity API rejected the request, Reason: Invalid IP (1)
- * @expectedExceptionCode 400
*/
public function getGeoNonStringIp()
{
+ $this->expectExceptionMessage('NetAcuity API rejected the request, Reason: Invalid IP (1)');
+ $this->expectExceptionCode(400);
+
$mockException = $this->getMockClientException(400, 'Invalid IP (1)');
$mockClient = $this->getMockGuzzleClient();
$mockClient->method('send')->will($this->throwException($mockException));
@@ -167,15 +167,13 @@ public function getGeoNonStringIp()
/**
* @test
- *
* @covers ::fetch
- *
- * @expectedException Exception
- * @expectedExceptionMessage NetAcuity API rejected the provided api user token.
- * @expectedExceptionCode 403
*/
public function netAcuityUserTokenInvalid()
{
+ $this->expectExceptionMessage('NetAcuity API rejected the provided api user token.');
+ $this->expectExceptionCode(403);
+
$mockException = $this->getMockClientException(403, 'Invalid IP (1)');
$mockClient = $this->getMockGuzzleClient();
$mockClient->method('send')->will($this->throwException($mockException));
diff --git a/tests/NetAcuityTest.php b/tests/NetAcuityTest.php
index ec4504c..0a951ba 100644
--- a/tests/NetAcuityTest.php
+++ b/tests/NetAcuityTest.php
@@ -2,13 +2,14 @@
namespace TraderInteractive\NetAcuity\Tests;
+use PHPUnit\Framework\TestCase;
use TraderInteractive\NetAcuity\NetAcuity;
/**
* @coversDefaultClass \TraderInteractive\NetAcuity\NetAcuity
* @covers ::__construct
*/
-final class NetAcuityTest extends NetAcuityTestSuite
+final class NetAcuityTest extends TestCase
{
/**
* @test
diff --git a/tests/NetAcuityTestSuite.php b/tests/NetAcuityTestSuite.php
index dd81bbd..fc4ece7 100644
--- a/tests/NetAcuityTestSuite.php
+++ b/tests/NetAcuityTestSuite.php
@@ -4,53 +4,28 @@
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
+use GuzzleHttp\Psr7\Request;
+use GuzzleHttp\Psr7\Response;
+use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
abstract class NetAcuityTestSuite extends TestCase
{
- protected function getMockGuzzleClient() : ClientInterface
+ protected function getMockGuzzleClient(): ClientInterface
{
- return $this->getMockBuilder(
- '\GuzzleHttp\Client'
- )->disableOriginalConstructor()->setMethods(['send'])->getMock();
+ return $this->getMockBuilder(ClientInterface::class)->getMock();
}
- protected function getMockClientException(int $code, string $errorMessage) : ClientException
+ protected function getMockClientException(int $code, string $errorMessage): ClientException
{
- $mockStream =$this->getMockBuilder(
- '\GuzzleHttp\Psr7\Stream'
- )->disableOriginalConstructor()->setMethods(['getContents'])->getMock();
- $mockStream->method(
- 'getContents'
- )->willReturn(json_encode(['error' => ['message' => $errorMessage]]));
-
- $mockResponse = $this->getMockBuilder(
- '\GuzzleHttp\Psr7\Response'
- )->disableOriginalConstructor()->setMethods(['getStatusCode', 'getBody'])->getMock();
- $mockResponse->method('getStatusCode')->willReturn($code);
- $mockResponse->method('getBody')->willReturn($mockStream);
-
- $mockException = $this->getMockBuilder(
- '\GuzzleHttp\Exception\ClientException'
- )->disableOriginalConstructor()->setMethods(['getResponse'])->getMock();
- $mockException->method('getResponse')->willReturn($mockResponse);
-
- return $mockException;
+ $stream = Utils::streamFor(json_encode(['error' => ['message' => $errorMessage]]));
+ $response = new Response($code, [], $stream);
+ return new ClientException($errorMessage, new Request('GET', 'localhost'), $response);
}
- protected function getMockResponse(array $response) : ResponseInterface
+ protected function getMockResponse(array $response): ResponseInterface
{
- $mockStream = $this->getMockBuilder(
- '\GuzzleHttp\Psr7\Stream'
- )->disableOriginalConstructor()->setMethods(['getContents'])->getMock();
- $mockStream->method('getContents')->willReturn(json_encode(['response' => $response], true));
-
- $mockResponse = $this->getMockBuilder(
- '\GuzzleHttp\Psr7\Response'
- )->disableOriginalConstructor()->setMethods(['getBody'])->getMock();
- $mockResponse->method('getBody')->willReturn($mockStream);
-
- return $mockResponse;
+ return new Response(200, [], Utils::streamFor(json_encode(['response' => $response])));
}
}