Skip to content

Commit bf0c302

Browse files
authored
Merge pull request #23 from chadicus/master
Add Support for PHP 8.x
2 parents d69275e + cd75257 commit bf0c302

File tree

10 files changed

+30
-58
lines changed

10 files changed

+30
-58
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
14+
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v2

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"sort-packages": true
1515
},
1616
"require": {
17-
"php": "^7.0",
18-
"traderinteractive/util": "^3.0",
19-
"guzzlehttp/guzzle": "^6.3"
17+
"php": "^7.0||^8.0",
18+
"guzzlehttp/guzzle": "^6.3",
19+
"traderinteractive/util-arrays": "^3.1||^4.0"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^6.0",
22+
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0 || ^9.0",
2323
"squizlabs/php_codesniffer": "^3.2"
2424
},
2525
"autoload": {

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<exclude-pattern>*/vendor/*</exclude-pattern>
55
<arg name="colors" />
66
<arg value="p" />
7-
<rule ref="PSR2" />
7+
<rule ref="PSR12" />
88
</ruleset>

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<phpunit colors="true" forceCoversAnnotation="true" strict="true">
1+
<phpunit colors="true" forceCoversAnnotation="true">
22
<testsuite name="Unit Tests">
33
<directory>./tests</directory>
44
</testsuite>

src/Databases/AbstractNetAcuityDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function parseBody(array $response)
115115
*
116116
* @return string The formatted url query string.
117117
*/
118-
protected function buildQuery(string $userToken, string $ip) : string
118+
protected function buildQuery(string $userToken, string $ip): string
119119
{
120120
$baseUrl = 'https://usa.cloud.netacuity.com/webservice/query';
121121
return "{$baseUrl}?u={$userToken}&dbs={$this->databaseIdentifier}&ip={$ip}&json=true";

src/NetAcuity.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace TraderInteractive\NetAcuity;
44

55
use TraderInteractive\NetAcuity\Databases\NetAcuityDatabaseInterface;
6-
use TraderInteractive\Util;
76
use Exception;
87

98
/**
@@ -59,9 +58,8 @@ public function __construct(NetAcuityDatabaseInterface $database)
5958
* @type string $timezone-name
6059
* }
6160
*/
62-
public function getGeo(string $ip) : array
61+
public function getGeo(string $ip): array
6362
{
64-
Util::throwIfNotType(['string' => $ip], true);
6563
return $this->database->fetch($ip);
6664
}
6765
}

src/NetAcuityInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ interface NetAcuityInterface
3939
* @type string $timezone-name
4040
* }
4141
*/
42-
public function getGeo(string $ip) : array;
42+
public function getGeo(string $ip): array;
4343
}

tests/Databases/AbstractNetAcuityDatabaseTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ public function getGeoWithExtraFieldEdge()
151151
*
152152
* @test
153153
* @covers ::fetch
154-
* @expectedException Exception
155-
* @expectedExceptionMessage NetAcuity API rejected the request, Reason: Invalid IP (1)
156-
* @expectedExceptionCode 400
157154
*/
158155
public function getGeoNonStringIp()
159156
{
157+
$this->expectExceptionMessage('NetAcuity API rejected the request, Reason: Invalid IP (1)');
158+
$this->expectExceptionCode(400);
159+
160160
$mockException = $this->getMockClientException(400, 'Invalid IP (1)');
161161
$mockClient = $this->getMockGuzzleClient();
162162
$mockClient->method('send')->will($this->throwException($mockException));
@@ -167,15 +167,13 @@ public function getGeoNonStringIp()
167167

168168
/**
169169
* @test
170-
*
171170
* @covers ::fetch
172-
*
173-
* @expectedException Exception
174-
* @expectedExceptionMessage NetAcuity API rejected the provided api user token.
175-
* @expectedExceptionCode 403
176171
*/
177172
public function netAcuityUserTokenInvalid()
178173
{
174+
$this->expectExceptionMessage('NetAcuity API rejected the provided api user token.');
175+
$this->expectExceptionCode(403);
176+
179177
$mockException = $this->getMockClientException(403, 'Invalid IP (1)');
180178
$mockClient = $this->getMockGuzzleClient();
181179
$mockClient->method('send')->will($this->throwException($mockException));

tests/NetAcuityTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace TraderInteractive\NetAcuity\Tests;
44

5+
use PHPUnit\Framework\TestCase;
56
use TraderInteractive\NetAcuity\NetAcuity;
67

78
/**
89
* @coversDefaultClass \TraderInteractive\NetAcuity\NetAcuity
910
* @covers ::__construct
1011
*/
11-
final class NetAcuityTest extends NetAcuityTestSuite
12+
final class NetAcuityTest extends TestCase
1213
{
1314
/**
1415
* @test

tests/NetAcuityTestSuite.php

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,28 @@
44

55
use GuzzleHttp\ClientInterface;
66
use GuzzleHttp\Exception\ClientException;
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Response;
9+
use GuzzleHttp\Psr7\Utils;
710
use PHPUnit\Framework\TestCase;
811
use Psr\Http\Message\ResponseInterface;
912

1013
abstract class NetAcuityTestSuite extends TestCase
1114
{
12-
protected function getMockGuzzleClient() : ClientInterface
15+
protected function getMockGuzzleClient(): ClientInterface
1316
{
14-
return $this->getMockBuilder(
15-
'\GuzzleHttp\Client'
16-
)->disableOriginalConstructor()->setMethods(['send'])->getMock();
17+
return $this->getMockBuilder(ClientInterface::class)->getMock();
1718
}
1819

19-
protected function getMockClientException(int $code, string $errorMessage) : ClientException
20+
protected function getMockClientException(int $code, string $errorMessage): ClientException
2021
{
21-
$mockStream =$this->getMockBuilder(
22-
'\GuzzleHttp\Psr7\Stream'
23-
)->disableOriginalConstructor()->setMethods(['getContents'])->getMock();
24-
$mockStream->method(
25-
'getContents'
26-
)->willReturn(json_encode(['error' => ['message' => $errorMessage]]));
27-
28-
$mockResponse = $this->getMockBuilder(
29-
'\GuzzleHttp\Psr7\Response'
30-
)->disableOriginalConstructor()->setMethods(['getStatusCode', 'getBody'])->getMock();
31-
$mockResponse->method('getStatusCode')->willReturn($code);
32-
$mockResponse->method('getBody')->willReturn($mockStream);
33-
34-
$mockException = $this->getMockBuilder(
35-
'\GuzzleHttp\Exception\ClientException'
36-
)->disableOriginalConstructor()->setMethods(['getResponse'])->getMock();
37-
$mockException->method('getResponse')->willReturn($mockResponse);
38-
39-
return $mockException;
22+
$stream = Utils::streamFor(json_encode(['error' => ['message' => $errorMessage]]));
23+
$response = new Response($code, [], $stream);
24+
return new ClientException($errorMessage, new Request('GET', 'localhost'), $response);
4025
}
4126

42-
protected function getMockResponse(array $response) : ResponseInterface
27+
protected function getMockResponse(array $response): ResponseInterface
4328
{
44-
$mockStream = $this->getMockBuilder(
45-
'\GuzzleHttp\Psr7\Stream'
46-
)->disableOriginalConstructor()->setMethods(['getContents'])->getMock();
47-
$mockStream->method('getContents')->willReturn(json_encode(['response' => $response], true));
48-
49-
$mockResponse = $this->getMockBuilder(
50-
'\GuzzleHttp\Psr7\Response'
51-
)->disableOriginalConstructor()->setMethods(['getBody'])->getMock();
52-
$mockResponse->method('getBody')->willReturn($mockStream);
53-
54-
return $mockResponse;
29+
return new Response(200, [], Utils::streamFor(json_encode(['response' => $response])));
5530
}
5631
}

0 commit comments

Comments
 (0)