Skip to content

Commit 613e38e

Browse files
committed
Add Support for PHP 8.x
1 parent 24a341c commit 613e38e

File tree

5 files changed

+20
-46
lines changed

5 files changed

+20
-46
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"sort-packages": true
1515
},
1616
"require": {
17-
"php": "^7.0",
17+
"php": "^7.0||^8.0",
1818
"guzzlehttp/guzzle": "^6.3",
19-
"traderinteractive/util-arrays": "^3.1"
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": {

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>

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: 8 additions & 33 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
{
1215
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

1920
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

4227
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)