Skip to content

Commit b728c8f

Browse files
committed
PHP8 support + PayloadTooLargeException
1 parent 04e85d8 commit b728c8f

File tree

5 files changed

+115
-7
lines changed

5 files changed

+115
-7
lines changed

.circleci/config.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ jobs:
1111
- run:
1212
name: Run tests / Symfony 4^3
1313
command: |
14-
composer update -n --prefer-dist --prefer-stable --no-suggest
14+
composer update -n --prefer-dist --prefer-stable
1515
php vendor/bin/phpunit
1616
1717
- run:
1818
name: Run tests / Symfony 5^0
1919
command: |
20-
composer update -n --prefer-dist --no-suggest
20+
composer update -n --prefer-dist
2121
php vendor/bin/phpunit
2222
2323
php74:
@@ -30,18 +30,32 @@ jobs:
3030
- run:
3131
name: Run tests / Symfony 4^3
3232
command: |
33-
composer update -n --prefer-dist --prefer-stable --no-suggest
33+
composer update -n --prefer-dist --prefer-stable
3434
php vendor/bin/phpunit
3535
3636
- run:
3737
name: Run tests / Symfony 5^0
3838
command: |
39-
composer update -n --prefer-dist --no-suggest
39+
composer update -n --prefer-dist
40+
php vendor/bin/phpunit
41+
42+
php80:
43+
docker:
44+
- image: circleci/php:8.0-cli
45+
46+
working_directory: ~/project
47+
steps:
48+
- checkout
49+
- run:
50+
name: Run tests
51+
command: |
52+
composer update -n --prefer-dist
4053
php vendor/bin/phpunit
4154
4255
workflows:
4356
version: 2
4457
test:
4558
jobs:
4659
- php72
47-
- php74
60+
- php74
61+
- php80
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch PHP Client.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Exception;
17+
18+
/**
19+
* Class EmptyBodyException.
20+
*/
21+
class PayloadTooLargeException extends TransportableException
22+
{
23+
/**
24+
* @return int
25+
*/
26+
public static function getTransportableHTTPError(): int
27+
{
28+
return 413;
29+
}
30+
31+
/**
32+
* @return self
33+
*/
34+
public static function create(): self
35+
{
36+
return new static('You sent us a too large payload. Please, consider reducing this size.');
37+
}
38+
}

Http/HttpResponsesToException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Apisearch\Exception\ForbiddenException;
2020
use Apisearch\Exception\InvalidFormatException;
2121
use Apisearch\Exception\InvalidTokenException;
22+
use Apisearch\Exception\PayloadTooLargeException;
2223
use Apisearch\Exception\ResourceExistsException;
2324
use Apisearch\Exception\ResourceNotAvailableException;
2425
use Apisearch\Exception\TooManyRequestsException;
@@ -60,6 +61,8 @@ protected static function throwTransportableExceptionIfNeeded(
6061
throw new ForbiddenException($response['body']['message']);
6162
case TooManyRequestsException::getTransportableHTTPError():
6263
throw new TooManyRequestsException($response['body']['message']);
64+
case PayloadTooLargeException::getTransportableHTTPError():
65+
throw new PayloadTooLargeException($response['body']['message']);
6366
case ConnectionException::getTransportableHTTPError():
6467
throw new ConnectionException('Apisearch returned an internal error code [500] - '.$response['body']['message']);
6568
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch PHP Client.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Tests\Exception;
17+
18+
use Apisearch\Exception\PayloadTooLargeException;
19+
use Apisearch\Exception\TransportableException;
20+
use PHPUnit\Framework\TestCase;
21+
22+
/**
23+
* Class PayloadTooLargeExceptionTest.
24+
*/
25+
class PayloadTooLargeExceptionTest extends TestCase
26+
{
27+
/**
28+
* Assert that returns proper transportable error.
29+
*/
30+
public function testTransportableErrorCode()
31+
{
32+
$this->assertInstanceOf(
33+
TransportableException::class,
34+
new PayloadTooLargeException()
35+
);
36+
37+
$this->assertEquals(
38+
413,
39+
PayloadTooLargeException::getTransportableHTTPError()
40+
);
41+
}
42+
43+
/**
44+
* Assert that extends an exception.
45+
*/
46+
public function testExtendsException()
47+
{
48+
$this->assertInstanceOf(
49+
\Exception::class,
50+
new PayloadTooLargeException()
51+
);
52+
}
53+
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.2",
13+
"php": "^7.2 | ^8.0",
1414
"ext-curl": "*",
1515
"symfony/event-dispatcher": "^3.4 || ^4.0 || ^5.0",
1616
"symfony/yaml": "^3.4 || ^4.0 || ^5.0",
1717
"nesbot/carbon": "^1.22 || ^2.0"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "7.5.17"
20+
"phpunit/phpunit": "^9"
2121
},
2222
"autoload": {
2323
"psr-4": {

0 commit comments

Comments
 (0)