Skip to content

Commit

Permalink
Merge pull request #52 from maxmind/greg/fix-lints
Browse files Browse the repository at this point in the history
Run new php-cs-fixer
  • Loading branch information
horgh authored Jan 5, 2024
2 parents 7f47064 + 80754ab commit 9013268
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
55 changes: 31 additions & 24 deletions tests/MaxMind/Test/WebService/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
putenv('XDEBUG_CONFIG=idekey=mock');

use Composer\CaBundle\CaBundle;
use MaxMind\Exception\AuthenticationException;
use MaxMind\Exception\HttpException;
use MaxMind\Exception\InsufficientFundsException;
use MaxMind\Exception\InvalidRequestException;
use MaxMind\Exception\PermissionRequiredException;
use MaxMind\Exception\WebServiceException;
use MaxMind\WebService\Client;
use MaxMind\WebService\Http\Request;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -259,15 +266,15 @@ public function testOptions(): void

public function test200PostWithInvalidJson(): void
{
$this->expectException(\MaxMind\Exception\WebServiceException::class);
$this->expectException(WebServiceException::class);
$this->expectExceptionMessage('Received a 200 response for TestService but could not decode the response as JSON: Syntax error. Body: {');

$this->withResponseTestServer(200, 'application/json', '{', 'post');
}

public function test200GetWithInvalidJson(): void
{
$this->expectException(\MaxMind\Exception\WebServiceException::class);
$this->expectException(WebServiceException::class);
$this->expectExceptionMessage('Received a 200 response for TestService but could not decode the response as JSON: Syntax error. Body: {');

$this->withResponseTestServer(200, 'application/json', '{', 'get');
Expand All @@ -277,15 +284,15 @@ public function test200GetWithInvalidJson(): void
// the built-in php server doesn't let us send a body when the http status is 204.
public function test204WithResponseBody(): void
{
$this->expectException(\MaxMind\Exception\WebServiceException::class);
$this->expectException(WebServiceException::class);
$this->expectExceptionMessage('Received a 204 response for TestService along with an unexpected HTTP body: non-empty response body');

$this->withResponse(204, 'application/json', 'non-empty response body');
}

public function testGetInsufficientFunds(): void
{
$this->expectException(\MaxMind\Exception\InsufficientFundsException::class);
$this->expectException(InsufficientFundsException::class);
$this->expectExceptionMessage('out of credit');

$this->withResponseTestServer(
Expand All @@ -298,7 +305,7 @@ public function testGetInsufficientFunds(): void

public function testPostInsufficientFunds(): void
{
$this->expectException(\MaxMind\Exception\InsufficientFundsException::class);
$this->expectException(InsufficientFundsException::class);
$this->expectExceptionMessage('out of credit');

$this->withResponseTestServer(
Expand All @@ -314,7 +321,7 @@ public function testPostInsufficientFunds(): void
*/
public function testPostInvalidAuth(string $code): void
{
$this->expectException(\MaxMind\Exception\AuthenticationException::class);
$this->expectException(AuthenticationException::class);
$this->expectExceptionMessage('Invalid auth');

$this->withResponseTestServer(
Expand All @@ -330,7 +337,7 @@ public function testPostInvalidAuth(string $code): void
*/
public function testGetInvalidAuth(string $code): void
{
$this->expectException(\MaxMind\Exception\AuthenticationException::class);
$this->expectException(AuthenticationException::class);
$this->expectExceptionMessage('Invalid auth');

$this->withResponseTestServer(
Expand All @@ -355,7 +362,7 @@ public function invalidAuthCodes(): array

public function testGetPermissionRequired(): void
{
$this->expectException(\MaxMind\Exception\PermissionRequiredException::class);
$this->expectException(PermissionRequiredException::class);
$this->expectExceptionMessage('Permission required');

$this->withResponseTestServer(
Expand All @@ -368,7 +375,7 @@ public function testGetPermissionRequired(): void

public function testPostPermissionRequired(): void
{
$this->expectException(\MaxMind\Exception\PermissionRequiredException::class);
$this->expectException(PermissionRequiredException::class);
$this->expectExceptionMessage('Permission required');

$this->withResponseTestServer(
Expand All @@ -381,7 +388,7 @@ public function testPostPermissionRequired(): void

public function testPostInvalidRequest(): void
{
$this->expectException(\MaxMind\Exception\InvalidRequestException::class);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('IP invalid');

$this->withResponseTestServer(
Expand All @@ -394,7 +401,7 @@ public function testPostInvalidRequest(): void

public function testGetInvalidRequest(): void
{
$this->expectException(\MaxMind\Exception\InvalidRequestException::class);
$this->expectException(InvalidRequestException::class);
$this->expectExceptionMessage('IP invalid');

$this->withResponseTestServer(
Expand All @@ -407,95 +414,95 @@ public function testGetInvalidRequest(): void

public function testPost400WithInvalidJson(): void
{
$this->expectException(\MaxMind\Exception\WebServiceException::class);
$this->expectException(WebServiceException::class);
$this->expectExceptionMessage('Received a 400 error for TestService but could not decode the response as JSON: Syntax error. Body: {"blah"}');

$this->withResponseTestServer(400, 'application/json', '{"blah"}', 'post');
}

public function testGet400WithInvalidJson(): void
{
$this->expectException(\MaxMind\Exception\WebServiceException::class);
$this->expectException(WebServiceException::class);
$this->expectExceptionMessage('Received a 400 error for TestService but could not decode the response as JSON: Syntax error. Body: {"blah"}');

$this->withResponseTestServer(400, 'application/json', '{"blah"}', 'get');
}

public function testPost400WithNoBody(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received a 400 error for TestService with no body');

$this->withResponseTestServer(400, 'application/json', '', 'post');
}

public function testGet400WithNoBody(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received a 400 error for TestService with no body');

$this->withResponseTestServer(400, 'application/json', '', 'get');
}

public function testPost400WithUnexpectedContentType(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received a 400 error for TestService with the following body: text');

$this->withResponseTestServer(400, 'text/plain', 'text', 'post');
}

public function testGet400WithUnexpectedContentType(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received a 400 error for TestService with the following body: text');

$this->withResponseTestServer(400, 'text/plain', 'text', 'get');
}

public function testPost400WithUnexpectedJson(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Error response contains JSON but it does not specify code or error keys: {"not":"expected"}');

$this->withResponseTestServer(400, 'application/json', '{"not":"expected"}', 'post');
}

public function testGet400WithUnexpectedJson(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Error response contains JSON but it does not specify code or error keys: {"not":"expected"}');

$this->withResponseTestServer(400, 'application/json', '{"not":"expected"}', 'get');
}

public function testPost300(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received an unexpected HTTP status (300) for TestService');

$this->withResponseTestServer(300, 'application/json', '', 'post');
}

public function testGet300(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received an unexpected HTTP status (300) for TestService');

$this->withResponseTestServer(300, 'application/json', '', 'get');
}

public function testPost500(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received a server error (500) for TestService');

$this->withResponseTestServer(500, 'application/json', '', 'post');
}

public function testGet500(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessage('Received a server error (500) for TestService');

$this->withResponseTestServer(500, 'application/json', '', 'get');
Expand Down Expand Up @@ -582,7 +589,7 @@ private function runRequest(
$url = 'https://' . $host . $path;

$stub = $this->createMock(
\MaxMind\WebService\Http\Request::class
Request::class
);

$stub->expects($this->once())
Expand Down
5 changes: 3 additions & 2 deletions tests/MaxMind/Test/WebService/Http/CurlRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MaxMind\Test\WebService\Http;

use MaxMind\Exception\HttpException;
use MaxMind\WebService\Http\CurlRequest;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -40,7 +41,7 @@ protected function setUp(): void

public function testGet(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessageMatches('/^cURL error.*invalid.host/');

$cr = new CurlRequest(
Expand All @@ -53,7 +54,7 @@ public function testGet(): void

public function testPost(): void
{
$this->expectException(\MaxMind\Exception\HttpException::class);
$this->expectException(HttpException::class);
$this->expectExceptionMessageMatches('/^cURL error.*invalid.host/');

$cr = new CurlRequest(
Expand Down

0 comments on commit 9013268

Please sign in to comment.