mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-23 15:40:33 -06:00
Migrated ListShortUrlsActionTest to use PHPUnit mocks
This commit is contained in:
parent
9c02ea8799
commit
01829c82ee
@ -8,9 +8,8 @@ use Cake\Chronos\Chronos;
|
|||||||
use Laminas\Diactoros\Response\JsonResponse;
|
use Laminas\Diactoros\Response\JsonResponse;
|
||||||
use Laminas\Diactoros\ServerRequestFactory;
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
use Pagerfanta\Adapter\ArrayAdapter;
|
use Pagerfanta\Adapter\ArrayAdapter;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
use Shlinkio\Shlink\Common\Paginator\Paginator;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
|
||||||
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
|
use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlsParams;
|
||||||
@ -21,16 +20,14 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|||||||
|
|
||||||
class ListShortUrlsActionTest extends TestCase
|
class ListShortUrlsActionTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private ListShortUrlsAction $action;
|
private ListShortUrlsAction $action;
|
||||||
private ObjectProphecy $service;
|
private MockObject $service;
|
||||||
|
|
||||||
protected function setUp(): void
|
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([
|
new ShortUrlStringifier([
|
||||||
'hostname' => 'doma.in',
|
'hostname' => 'doma.in',
|
||||||
'schema' => 'https',
|
'schema' => 'https',
|
||||||
@ -54,7 +51,7 @@ class ListShortUrlsActionTest extends TestCase
|
|||||||
$apiKey = ApiKey::create();
|
$apiKey = ApiKey::create();
|
||||||
$request = ServerRequestFactory::fromGlobals()->withQueryParams($query)
|
$request = ServerRequestFactory::fromGlobals()->withQueryParams($query)
|
||||||
->withAttribute(ApiKey::class, $apiKey);
|
->withAttribute(ApiKey::class, $apiKey);
|
||||||
$listShortUrls = $this->service->listShortUrls(ShortUrlsParams::fromRawData([
|
$this->service->expects($this->once())->method('listShortUrls')->with(ShortUrlsParams::fromRawData([
|
||||||
'page' => $expectedPage,
|
'page' => $expectedPage,
|
||||||
'searchTerm' => $expectedSearchTerm,
|
'searchTerm' => $expectedSearchTerm,
|
||||||
'tags' => $expectedTags,
|
'tags' => $expectedTags,
|
||||||
@ -71,7 +68,6 @@ class ListShortUrlsActionTest extends TestCase
|
|||||||
self::assertArrayHasKey('data', $payload['shortUrls']);
|
self::assertArrayHasKey('data', $payload['shortUrls']);
|
||||||
self::assertEquals([], $payload['shortUrls']['data']);
|
self::assertEquals([], $payload['shortUrls']['data']);
|
||||||
self::assertEquals(200, $response->getStatusCode());
|
self::assertEquals(200, $response->getStatusCode());
|
||||||
$listShortUrls->shouldHaveBeenCalledOnce();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideFilteringData(): iterable
|
public function provideFilteringData(): iterable
|
||||||
|
Loading…
Reference in New Issue
Block a user