From 9c02ea87993326151d6e7e5f775415b70b3088b1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 22:12:27 +0200 Subject: [PATCH] Migrated EditShortUrlActionTest to use PHPUnit mocks --- .../Action/ShortUrl/EditShortUrlActionTest.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php index 19cb27e9..94f3dbae 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php @@ -5,10 +5,8 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\ServerRequest; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Exception\ValidationException; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; @@ -19,15 +17,13 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class EditShortUrlActionTest extends TestCase { - use ProphecyTrait; - private EditShortUrlAction $action; - private ObjectProphecy $shortUrlService; + private MockObject $shortUrlService; protected function setUp(): void { - $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); - $this->action = new EditShortUrlAction($this->shortUrlService->reveal(), new ShortUrlDataTransformer( + $this->shortUrlService = $this->createMock(ShortUrlServiceInterface::class); + $this->action = new EditShortUrlAction($this->shortUrlService, new ShortUrlDataTransformer( new ShortUrlStringifier([]), )); } @@ -38,6 +34,7 @@ class EditShortUrlActionTest extends TestCase $request = (new ServerRequest())->withParsedBody([ 'maxVisits' => 'invalid', ]); + $this->shortUrlService->expects($this->never())->method('updateShortUrl'); $this->expectException(ValidationException::class); @@ -52,13 +49,10 @@ class EditShortUrlActionTest extends TestCase ->withParsedBody([ 'maxVisits' => 5, ]); - $updateMeta = $this->shortUrlService->updateShortUrl(Argument::cetera())->willReturn( - ShortUrl::createEmpty(), - ); + $this->shortUrlService->expects($this->once())->method('updateShortUrl')->willReturn(ShortUrl::createEmpty()); $resp = $this->action->handle($request); self::assertEquals(200, $resp->getStatusCode()); - $updateMeta->shouldHaveBeenCalled(); } }