mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Improved ListShortUrlsActionTest covering different scenarios in which date ranges are provided
This commit is contained in:
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Service\ShortUrlService;
|
||||
use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
@@ -43,14 +45,15 @@ class ListShortUrlsActionTest extends TestCase
|
||||
int $expectedPage,
|
||||
?string $expectedSearchTerm,
|
||||
array $expectedTags,
|
||||
?string $expectedOrderBy
|
||||
?string $expectedOrderBy,
|
||||
DateRange $expectedDateRange
|
||||
): void {
|
||||
$listShortUrls = $this->service->listShortUrls(
|
||||
$expectedPage,
|
||||
$expectedSearchTerm,
|
||||
$expectedTags,
|
||||
$expectedOrderBy,
|
||||
null
|
||||
$expectedDateRange
|
||||
)->willReturn(new Paginator(new ArrayAdapter()));
|
||||
|
||||
/** @var JsonResponse $response */
|
||||
@@ -66,17 +69,44 @@ class ListShortUrlsActionTest extends TestCase
|
||||
|
||||
public function provideFilteringData(): iterable
|
||||
{
|
||||
yield [[], 1, null, [], null];
|
||||
yield [['page' => 10], 10, null, [], null];
|
||||
yield [['page' => null], 1, null, [], null];
|
||||
yield [['page' => '8'], 8, null, [], null];
|
||||
yield [['searchTerm' => $searchTerm = 'foo'], 1, $searchTerm, [], null];
|
||||
yield [['tags' => $tags = ['foo','bar']], 1, null, $tags, null];
|
||||
yield [['orderBy' => $orderBy = 'something'], 1, null, [], $orderBy];
|
||||
yield [[], 1, null, [], null, new DateRange()];
|
||||
yield [['page' => 10], 10, null, [], null, new DateRange()];
|
||||
yield [['page' => null], 1, null, [], null, new DateRange()];
|
||||
yield [['page' => '8'], 8, null, [], null, new DateRange()];
|
||||
yield [['searchTerm' => $searchTerm = 'foo'], 1, $searchTerm, [], null, new DateRange()];
|
||||
yield [['tags' => $tags = ['foo','bar']], 1, null, $tags, null, new DateRange()];
|
||||
yield [['orderBy' => $orderBy = 'something'], 1, null, [], $orderBy, new DateRange()];
|
||||
yield [[
|
||||
'page' => '2',
|
||||
'orderBy' => $orderBy = 'something',
|
||||
'tags' => $tags = ['one', 'two'],
|
||||
], 2, null, $tags, $orderBy];
|
||||
], 2, null, $tags, $orderBy, new DateRange()];
|
||||
yield [
|
||||
['startDate' => $date = Chronos::now()->toAtomString()],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
null,
|
||||
new DateRange(Chronos::parse($date)),
|
||||
];
|
||||
yield [
|
||||
['endDate' => $date = Chronos::now()->toAtomString()],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
null,
|
||||
new DateRange(null, Chronos::parse($date)),
|
||||
];
|
||||
yield [
|
||||
[
|
||||
'startDate' => $startDate = Chronos::now()->subDays(10)->toAtomString(),
|
||||
'endDate' => $endDate = Chronos::now()->toAtomString(),
|
||||
],
|
||||
1,
|
||||
null,
|
||||
[],
|
||||
null,
|
||||
new DateRange(Chronos::parse($startDate), Chronos::parse($endDate)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user