Migrated ListShortUrlsActionTest to use PHPUnit mocks

This commit is contained in:
Alejandro Celaya 2022-10-23 22:13:27 +02:00
parent 9c02ea8799
commit 01829c82ee

View File

@ -8,9 +8,8 @@ use Cake\Chronos\Chronos;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\Diactoros\ServerRequestFactory;
use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Common\Paginator\Paginator;
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
@ -21,16 +20,14 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
class ListShortUrlsActionTest extends TestCase
{
use ProphecyTrait;
private ListShortUrlsAction $action;
private ObjectProphecy $service;
private MockObject $service;
protected function setUp(): void
{
$this->service = $this->prophesize(ShortUrlService::class);
$this->service = $this->createMock(ShortUrlService::class);
$this->action = new ListShortUrlsAction($this->service->reveal(), new ShortUrlDataTransformer(
$this->action = new ListShortUrlsAction($this->service, new ShortUrlDataTransformer(
new ShortUrlStringifier([
'hostname' => 'doma.in',
'schema' => 'https',
@ -54,7 +51,7 @@ class ListShortUrlsActionTest extends TestCase
$apiKey = ApiKey::create();
$request = ServerRequestFactory::fromGlobals()->withQueryParams($query)
->withAttribute(ApiKey::class, $apiKey);
$listShortUrls = $this->service->listShortUrls(ShortUrlsParams::fromRawData([
$this->service->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
'page' => $expectedPage,
'searchTerm' => $expectedSearchTerm,
'tags' => $expectedTags,
@ -71,7 +68,6 @@ class ListShortUrlsActionTest extends TestCase
self::assertArrayHasKey('data', $payload['shortUrls']);
self::assertEquals([], $payload['shortUrls']['data']);
self::assertEquals(200, $response->getStatusCode());
$listShortUrls->shouldHaveBeenCalledOnce();
}
public function provideFilteringData(): iterable