From 01829c82ee60bc2124b19010fd0d70c18b407080 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 22:13:27 +0200 Subject: [PATCH] Migrated ListShortUrlsActionTest to use PHPUnit mocks --- .../Action/ShortUrl/ListShortUrlsActionTest.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 65e6ebbf..068677d3 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -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