Skip to content

Commit a7cbcfc

Browse files
authored
Merge pull request #132 from apisearch-io/feature/to-php8-payload-too-large-exception
PHP8 support + PayloadTooLargeException
2 parents d6f46b4 + ed97b1e commit a7cbcfc

File tree

5 files changed

+107
-18
lines changed

5 files changed

+107
-18
lines changed

.circleci/config.yml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,42 @@
11
version: 2
22

33
jobs:
4-
php72:
4+
5+
php74:
56
docker:
6-
- image: circleci/php:7.2-cli
7+
- image: circleci/php:7.4-cli
78

89
working_directory: ~/project
910
steps:
1011
- checkout
1112
- run:
1213
name: Run tests / Symfony 4^3
1314
command: |
14-
composer update -n --prefer-dist --prefer-stable --no-suggest
15+
composer update -n --prefer-dist --prefer-stable
1516
php vendor/bin/phpunit
1617
1718
- run:
1819
name: Run tests / Symfony 5^0
1920
command: |
20-
composer update -n --prefer-dist --no-suggest
21+
composer update -n --prefer-dist
2122
php vendor/bin/phpunit
2223
23-
php74:
24+
php80:
2425
docker:
25-
- image: circleci/php:7.4-cli
26+
- image: circleci/php:8.0-cli
2627

2728
working_directory: ~/project
2829
steps:
2930
- checkout
3031
- run:
31-
name: Run tests / Symfony 4^3
32-
command: |
33-
composer update -n --prefer-dist --prefer-stable --no-suggest
34-
php vendor/bin/phpunit
35-
36-
- run:
37-
name: Run tests / Symfony 5^0
32+
name: Run tests
3833
command: |
39-
composer update -n --prefer-dist --no-suggest
34+
composer update -n --prefer-dist
4035
php vendor/bin/phpunit
4136
4237
workflows:
4338
version: 2
4439
test:
4540
jobs:
46-
- php72
47-
- php74
41+
- php74
42+
- 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.4 | ^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)