mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Increased MIS to 83%
This commit is contained in:
@@ -38,7 +38,7 @@ class ListTagsAction extends AbstractRestAction
|
||||
}
|
||||
|
||||
$tagsInfo = $this->tagService->tagsInfo($apiKey);
|
||||
$data = map($tagsInfo, fn (TagInfo $info) => (string) $info->tag());
|
||||
$data = map($tagsInfo, static fn (TagInfo $info) => $info->tag()->__toString());
|
||||
|
||||
return new JsonResponse([
|
||||
'tags' => [
|
||||
|
||||
@@ -54,7 +54,7 @@ class BodyParserMiddleware implements MiddlewareInterface, RequestMethodInterfac
|
||||
|
||||
private function parseFromJson(Request $request): Request
|
||||
{
|
||||
$rawBody = (string) $request->getBody();
|
||||
$rawBody = $request->getBody()->__toString();
|
||||
if (empty($rawBody)) {
|
||||
return $request;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ class BodyParserMiddleware implements MiddlewareInterface, RequestMethodInterfac
|
||||
*/
|
||||
private function parseFromUrlEncoded(Request $request): Request
|
||||
{
|
||||
$rawBody = (string) $request->getBody();
|
||||
$rawBody = $request->getBody()->__toString();
|
||||
if (empty($rawBody)) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\Domain\Request;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface;
|
||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||
use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions;
|
||||
use Shlinkio\Shlink\Rest\Action\Domain\Request\DomainRedirectsRequest;
|
||||
|
||||
class DomainRedirectsRequestTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideInvalidData
|
||||
*/
|
||||
public function throwsExceptionWhenCreatingWithInvalidData(array $data): void
|
||||
{
|
||||
$this->expectException(ValidationException::class);
|
||||
DomainRedirectsRequest::fromRawData($data);
|
||||
}
|
||||
|
||||
public function provideInvalidData(): iterable
|
||||
{
|
||||
yield 'missing domain' => [[]];
|
||||
yield 'invalid domain' => [['domain' => 'foo:bar:baz']];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideValidData
|
||||
*/
|
||||
public function isProperlyCastToNotFoundRedirects(
|
||||
array $data,
|
||||
?NotFoundRedirectConfigInterface $defaults,
|
||||
string $expectedAuthority,
|
||||
?string $expectedBaseUrlRedirect,
|
||||
?string $expectedRegular404Redirect,
|
||||
?string $expectedInvalidShortUrlRedirect,
|
||||
): void {
|
||||
$request = DomainRedirectsRequest::fromRawData($data);
|
||||
$notFound = $request->toNotFoundRedirects($defaults);
|
||||
|
||||
self::assertEquals($expectedAuthority, $request->authority());
|
||||
self::assertEquals($expectedBaseUrlRedirect, $notFound->baseUrlRedirect());
|
||||
self::assertEquals($expectedRegular404Redirect, $notFound->regular404Redirect());
|
||||
self::assertEquals($expectedInvalidShortUrlRedirect, $notFound->invalidShortUrlRedirect());
|
||||
}
|
||||
|
||||
public function provideValidData(): iterable
|
||||
{
|
||||
yield 'no values' => [['domain' => 'foo'], null, 'foo', null, null, null];
|
||||
yield 'some values' => [['domain' => 'foo', 'regular404Redirect' => 'bar'], null, 'foo', null, 'bar', null];
|
||||
yield 'fallbacks' => [
|
||||
['domain' => 'domain', 'baseUrlRedirect' => 'bar'],
|
||||
new NotFoundRedirectOptions(['regular404' => 'fallback', 'invalidShortUrl' => 'fallback2']),
|
||||
'domain',
|
||||
'bar',
|
||||
'fallback',
|
||||
'fallback2',
|
||||
];
|
||||
yield 'fallback ignored' => [
|
||||
['domain' => 'domain', 'regular404Redirect' => 'bar', 'invalidShortUrlRedirect' => null],
|
||||
new NotFoundRedirectOptions(['regular404' => 'fallback', 'invalidShortUrl' => 'fallback2']),
|
||||
'domain',
|
||||
null,
|
||||
'bar',
|
||||
null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user