From 1ebaeb728e66f4981c4877e1bb202e3330385104 Mon Sep 17 00:00:00 2001 From: chadicus Date: Tue, 1 Jul 2025 10:03:54 -0400 Subject: [PATCH 1/6] Use ubuntu latest in php workflows --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f6cc126..6b0324b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -8,7 +8,7 @@ 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'] From 2f63cc22329752f5b02a0b82e1c5e07d076c8e25 Mon Sep 17 00:00:00 2001 From: chadicus Date: Tue, 1 Jul 2025 10:07:28 -0400 Subject: [PATCH 2/6] Remove call to Util::throwIfNotType as it is unecessary with type hints --- src/NetAcuity.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NetAcuity.php b/src/NetAcuity.php index c26dc63..7041ed9 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; /** @@ -61,7 +60,6 @@ public function __construct(NetAcuityDatabaseInterface $database) */ public function getGeo(string $ip) : array { - Util::throwIfNotType(['string' => $ip], true); return $this->database->fetch($ip); } } From 98bc3d448f5993226baca182bccfb46599ba00f9 Mon Sep 17 00:00:00 2001 From: chadicus Date: Tue, 1 Jul 2025 10:08:39 -0400 Subject: [PATCH 3/6] Remove traderinteractive/util and add traderinteractive/util-arrays --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 89ad081..fd52c96 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ }, "require": { "php": "^7.0", - "traderinteractive/util": "^3.0", - "guzzlehttp/guzzle": "^6.3" + "guzzlehttp/guzzle": "^6.3", + "traderinteractive/util-arrays": "^3.1" }, "require-dev": { "phpunit/phpunit": "^6.0", From 24a341c9fa5ba6d0d04b35f31d4349bcbc3a8138 Mon Sep 17 00:00:00 2001 From: chadicus Date: Tue, 1 Jul 2025 10:12:17 -0400 Subject: [PATCH 4/6] Switch to PSR-12 coding standard --- phpcs.xml | 2 +- src/Databases/AbstractNetAcuityDatabase.php | 2 +- src/NetAcuity.php | 2 +- src/NetAcuityInterface.php | 2 +- tests/NetAcuityTestSuite.php | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) 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/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 7041ed9..17dfe9a 100644 --- a/src/NetAcuity.php +++ b/src/NetAcuity.php @@ -58,7 +58,7 @@ public function __construct(NetAcuityDatabaseInterface $database) * @type string $timezone-name * } */ - public function getGeo(string $ip) : array + public function getGeo(string $ip): array { 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/NetAcuityTestSuite.php b/tests/NetAcuityTestSuite.php index dd81bbd..8084048 100644 --- a/tests/NetAcuityTestSuite.php +++ b/tests/NetAcuityTestSuite.php @@ -9,16 +9,16 @@ abstract class NetAcuityTestSuite extends TestCase { - protected function getMockGuzzleClient() : ClientInterface + protected function getMockGuzzleClient(): ClientInterface { return $this->getMockBuilder( '\GuzzleHttp\Client' )->disableOriginalConstructor()->setMethods(['send'])->getMock(); } - protected function getMockClientException(int $code, string $errorMessage) : ClientException + protected function getMockClientException(int $code, string $errorMessage): ClientException { - $mockStream =$this->getMockBuilder( + $mockStream = $this->getMockBuilder( '\GuzzleHttp\Psr7\Stream' )->disableOriginalConstructor()->setMethods(['getContents'])->getMock(); $mockStream->method( @@ -39,7 +39,7 @@ protected function getMockClientException(int $code, string $errorMessage) : Cli return $mockException; } - protected function getMockResponse(array $response) : ResponseInterface + protected function getMockResponse(array $response): ResponseInterface { $mockStream = $this->getMockBuilder( '\GuzzleHttp\Psr7\Stream' From 613e38eff7191e8d8dbb70ca5b7513c1210c0d94 Mon Sep 17 00:00:00 2001 From: chadicus Date: Tue, 1 Jul 2025 10:48:18 -0400 Subject: [PATCH 5/6] Add Support for PHP 8.x --- composer.json | 6 +-- phpunit.xml.dist | 2 +- .../AbstractNetAcuityDatabaseTest.php | 14 +++---- tests/NetAcuityTest.php | 3 +- tests/NetAcuityTestSuite.php | 41 ++++--------------- 5 files changed, 20 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index fd52c96..53f0f92 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ "sort-packages": true }, "require": { - "php": "^7.0", + "php": "^7.0||^8.0", "guzzlehttp/guzzle": "^6.3", - "traderinteractive/util-arrays": "^3.1" + "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/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/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 8084048..fc4ece7 100644 --- a/tests/NetAcuityTestSuite.php +++ b/tests/NetAcuityTestSuite.php @@ -4,6 +4,9 @@ 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; @@ -11,46 +14,18 @@ abstract class NetAcuityTestSuite extends TestCase { 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 { - $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 { - $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]))); } } From cd752576c7a9bfcba972e4d142631df104f80436 Mon Sep 17 00:00:00 2001 From: chadicus Date: Tue, 1 Jul 2025 10:49:11 -0400 Subject: [PATCH 6/6] Add PHP 8.x to github action workflow --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 6b0324b..2d4fede 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,7 +11,7 @@ jobs: 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