Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
version: 2

jobs:
php72:

php74:
docker:
- image: circleci/php:7.2-cli
- image: circleci/php:7.4-cli

working_directory: ~/project
steps:
- checkout
- 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
- php74
- php80
38 changes: 38 additions & 0 deletions Exception/PayloadTooLargeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Apisearch PHP Client.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

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.');
}
}
3 changes: 3 additions & 0 deletions Http/HttpResponsesToException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}
Expand Down
53 changes: 53 additions & 0 deletions Tests/Exception/PayloadTooLargeExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the Apisearch PHP Client.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

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()
);
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down