diff --git a/.circleci/config.yml b/.circleci/config.yml index 8c6e548..84d3a68 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,9 +1,10 @@ version: 2 jobs: - php72: + + php74: docker: - - image: circleci/php:7.2-cli + - image: circleci/php:7.4-cli working_directory: ~/project steps: @@ -11,37 +12,31 @@ jobs: - run: name: Run tests / Symfony 4^3 command: | - composer update -n --prefer-dist --prefer-stable --no-suggest + composer update -n --prefer-dist --prefer-stable php vendor/bin/phpunit - run: name: Run tests / Symfony 5^0 command: | - composer update -n --prefer-dist --no-suggest + composer update -n --prefer-dist php vendor/bin/phpunit - php74: + php80: docker: - - image: circleci/php:7.4-cli + - image: circleci/php:8.0-cli working_directory: ~/project steps: - checkout - run: - name: Run tests / Symfony 4^3 - command: | - composer update -n --prefer-dist --prefer-stable --no-suggest - php vendor/bin/phpunit - - - run: - name: Run tests / Symfony 5^0 + name: Run tests command: | - composer update -n --prefer-dist --no-suggest + composer update -n --prefer-dist php vendor/bin/phpunit workflows: version: 2 test: jobs: - - php72 - - php74 \ No newline at end of file + - php74 + - php80 \ No newline at end of file diff --git a/Exception/PayloadTooLargeException.php b/Exception/PayloadTooLargeException.php new file mode 100644 index 0000000..a060efb --- /dev/null +++ b/Exception/PayloadTooLargeException.php @@ -0,0 +1,38 @@ + + */ + +declare(strict_types=1); + +namespace Apisearch\Exception; + +/** + * Class EmptyBodyException. + */ +class PayloadTooLargeException extends TransportableException +{ + /** + * @return int + */ + public static function getTransportableHTTPError(): int + { + return 413; + } + + /** + * @return self + */ + public static function create(): self + { + return new static('You sent us a too large payload. Please, consider reducing this size.'); + } +} diff --git a/Http/HttpResponsesToException.php b/Http/HttpResponsesToException.php index fe57a20..24866e8 100644 --- a/Http/HttpResponsesToException.php +++ b/Http/HttpResponsesToException.php @@ -19,6 +19,7 @@ use Apisearch\Exception\ForbiddenException; use Apisearch\Exception\InvalidFormatException; use Apisearch\Exception\InvalidTokenException; +use Apisearch\Exception\PayloadTooLargeException; use Apisearch\Exception\ResourceExistsException; use Apisearch\Exception\ResourceNotAvailableException; use Apisearch\Exception\TooManyRequestsException; @@ -60,6 +61,8 @@ protected static function throwTransportableExceptionIfNeeded( throw new ForbiddenException($response['body']['message']); case TooManyRequestsException::getTransportableHTTPError(): throw new TooManyRequestsException($response['body']['message']); + case PayloadTooLargeException::getTransportableHTTPError(): + throw new PayloadTooLargeException($response['body']['message']); case ConnectionException::getTransportableHTTPError(): throw new ConnectionException('Apisearch returned an internal error code [500] - '.$response['body']['message']); } diff --git a/Tests/Exception/PayloadTooLargeExceptionTest.php b/Tests/Exception/PayloadTooLargeExceptionTest.php new file mode 100644 index 0000000..9692150 --- /dev/null +++ b/Tests/Exception/PayloadTooLargeExceptionTest.php @@ -0,0 +1,53 @@ + + */ + +declare(strict_types=1); + +namespace Apisearch\Tests\Exception; + +use Apisearch\Exception\PayloadTooLargeException; +use Apisearch\Exception\TransportableException; +use PHPUnit\Framework\TestCase; + +/** + * Class PayloadTooLargeExceptionTest. + */ +class PayloadTooLargeExceptionTest extends TestCase +{ + /** + * Assert that returns proper transportable error. + */ + public function testTransportableErrorCode() + { + $this->assertInstanceOf( + TransportableException::class, + new PayloadTooLargeException() + ); + + $this->assertEquals( + 413, + PayloadTooLargeException::getTransportableHTTPError() + ); + } + + /** + * Assert that extends an exception. + */ + public function testExtendsException() + { + $this->assertInstanceOf( + \Exception::class, + new PayloadTooLargeException() + ); + } +} diff --git a/composer.json b/composer.json index d381fc1..6694f8c 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,14 @@ } ], "require": { - "php": ">=7.2", + "php": "^7.4 | ^8.0", "ext-curl": "*", "symfony/event-dispatcher": "^3.4 || ^4.0 || ^5.0", "symfony/yaml": "^3.4 || ^4.0 || ^5.0", "nesbot/carbon": "^1.22 || ^2.0" }, "require-dev": { - "phpunit/phpunit": "7.5.17" + "phpunit/phpunit": "^9" }, "autoload": { "psr-4": {