mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-25 18:30:23 -06:00
Updated ListTagsActionTest
This commit is contained in:
parent
2e269bcacd
commit
91aaffc6db
@ -25,16 +25,6 @@ final class TagInfo implements JsonSerializable
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
public function shortUrlsCount(): int
|
||||
{
|
||||
return $this->shortUrlsCount;
|
||||
}
|
||||
|
||||
public function visitsCount(): int
|
||||
{
|
||||
return $this->visitsCount;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
|
@ -4,15 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Rest\Action\Tag;
|
||||
|
||||
use Laminas\Diactoros\ServerRequest;
|
||||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
use Shlinkio\Shlink\Core\Tag\Model\TagInfo;
|
||||
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
|
||||
use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction;
|
||||
|
||||
use function Shlinkio\Shlink\Common\json_decode;
|
||||
|
||||
class ListTagsActionTest extends TestCase
|
||||
{
|
||||
private ListTagsAction $action;
|
||||
@ -24,18 +24,53 @@ class ListTagsActionTest extends TestCase
|
||||
$this->action = new ListTagsAction($this->tagService->reveal());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function returnsDataFromService(): void
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideNoStatsQueries
|
||||
*/
|
||||
public function returnsBaseDataWhenStatsAreNotRequested(array $query): void
|
||||
{
|
||||
$listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]);
|
||||
$tags = [new Tag('foo'), new Tag('bar')];
|
||||
$listTags = $this->tagService->listTags()->willReturn($tags);
|
||||
|
||||
$resp = $this->action->handle(new ServerRequest());
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams($query));
|
||||
$payload = $resp->getPayload();
|
||||
|
||||
$this->assertEquals([
|
||||
'tags' => [
|
||||
'data' => $tags,
|
||||
],
|
||||
], $payload);
|
||||
$listTags->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
public function provideNoStatsQueries(): iterable
|
||||
{
|
||||
yield 'no query' => [[]];
|
||||
yield 'withStats is false' => [['withStats' => 'withStats']];
|
||||
yield 'withStats is something else' => [['withStats' => 'foo']];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function returnsStatsWhenRequested(): void
|
||||
{
|
||||
$stats = [
|
||||
new TagInfo(new Tag('foo'), 1, 1),
|
||||
new TagInfo(new Tag('bar'), 3, 10),
|
||||
];
|
||||
$tagsInfo = $this->tagService->tagsInfo()->willReturn($stats);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams(['withStats' => 'true']));
|
||||
$payload = $resp->getPayload();
|
||||
|
||||
$this->assertEquals([
|
||||
'tags' => [
|
||||
'data' => ['foo', 'bar'],
|
||||
'stats' => $stats,
|
||||
],
|
||||
], json_decode((string) $resp->getBody()));
|
||||
$listTags->shouldHaveBeenCalled();
|
||||
], $payload);
|
||||
$tagsInfo->shouldHaveBeenCalled();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user