mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Migrated TagsStatsActionTest to use PHPUnit mocks
This commit is contained in:
parent
656083cb6f
commit
69e994c067
1 changed files with 8 additions and 12 deletions
|
@ -7,10 +7,8 @@ namespace ShlinkioTest\Shlink\Rest\Action\Tag;
|
|||
use Laminas\Diactoros\Response\JsonResponse;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Pagerfanta\Adapter\ArrayAdapter;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||
use Shlinkio\Shlink\Core\Tag\Model\TagInfo;
|
||||
|
@ -22,15 +20,13 @@ use function count;
|
|||
|
||||
class TagsStatsActionTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
private TagsStatsAction $action;
|
||||
private ObjectProphecy $tagService;
|
||||
private MockObject $tagService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->tagService = $this->prophesize(TagServiceInterface::class);
|
||||
$this->action = new TagsStatsAction($this->tagService->reveal());
|
||||
$this->tagService = $this->createMock(TagServiceInterface::class);
|
||||
$this->action = new TagsStatsAction($this->tagService);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -41,9 +37,10 @@ class TagsStatsActionTest extends TestCase
|
|||
new TagInfo('bar', 3, 10),
|
||||
];
|
||||
$itemsCount = count($stats);
|
||||
$tagsInfo = $this->tagService->tagsInfo(Argument::any(), Argument::type(ApiKey::class))->willReturn(
|
||||
new Paginator(new ArrayAdapter($stats)),
|
||||
);
|
||||
$this->tagService->expects($this->once())->method('tagsInfo')->with(
|
||||
$this->anything(),
|
||||
$this->isInstanceOf(ApiKey::class),
|
||||
)->willReturn(new Paginator(new ArrayAdapter($stats)));
|
||||
$req = $this->requestWithApiKey()->withQueryParams(['withStats' => 'true']);
|
||||
|
||||
/** @var JsonResponse $resp */
|
||||
|
@ -62,7 +59,6 @@ class TagsStatsActionTest extends TestCase
|
|||
],
|
||||
],
|
||||
], $payload);
|
||||
$tagsInfo->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
private function requestWithApiKey(): ServerRequestInterface
|
||||
|
|
Loading…
Add table
Reference in a new issue