2023-01-02 06:33:24 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Exception;
|
|
|
|
|
|
|
|
use Fig\Http\Message\StatusCodeInterface;
|
|
|
|
use JsonException;
|
2023-02-09 13:42:18 -06:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2023-01-02 06:33:24 -06:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Exception\MalformedBodyException;
|
|
|
|
|
|
|
|
class MalformedBodyExceptionTest extends TestCase
|
|
|
|
{
|
2023-02-09 13:42:18 -06:00
|
|
|
#[Test]
|
2023-01-02 06:33:24 -06:00
|
|
|
public function createsExpectedException(): void
|
|
|
|
{
|
|
|
|
$prev = new JsonException();
|
|
|
|
$e = MalformedBodyException::forInvalidJson($prev);
|
|
|
|
|
|
|
|
self::assertEquals($prev, $e->getPrevious());
|
|
|
|
self::assertEquals('Provided request does not contain a valid JSON body.', $e->getMessage());
|
|
|
|
self::assertEquals('Provided request does not contain a valid JSON body.', $e->getDetail());
|
|
|
|
self::assertEquals('Malformed request body', $e->getTitle());
|
|
|
|
self::assertEquals('https://shlink.io/api/error/malformed-request-body', $e->getType());
|
|
|
|
self::assertEquals(StatusCodeInterface::STATUS_BAD_REQUEST, $e->getStatus());
|
|
|
|
}
|
|
|
|
}
|