From acc9cb94b5dd5c568160bf855a363538dbb8b10b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 22:14:28 +0200 Subject: [PATCH] Migrated ResolveShortUrlActionTest to use PHPUnit mocks --- .../ShortUrl/ResolveShortUrlActionTest.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index 1b805c5f..0e91290f 100644 --- a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -5,9 +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\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; @@ -18,15 +17,13 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ResolveShortUrlActionTest extends TestCase { - use ProphecyTrait; - private ResolveShortUrlAction $action; - private ObjectProphecy $urlResolver; + private MockObject $urlResolver; protected function setUp(): void { - $this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class); - $this->action = new ResolveShortUrlAction($this->urlResolver->reveal(), new ShortUrlDataTransformer( + $this->urlResolver = $this->createMock(ShortUrlResolverInterface::class); + $this->action = new ResolveShortUrlAction($this->urlResolver, new ShortUrlDataTransformer( new ShortUrlStringifier([]), )); } @@ -36,11 +33,10 @@ class ResolveShortUrlActionTest extends TestCase { $shortCode = 'abc123'; $apiKey = ApiKey::create(); - $this->urlResolver->resolveShortUrl( + $this->urlResolver->expects($this->once())->method('resolveShortUrl')->with( ShortUrlIdentifier::fromShortCodeAndDomain($shortCode), $apiKey, - )->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar')) - ->shouldBeCalledOnce(); + )->willReturn(ShortUrl::withLongUrl('http://domain.com/foo/bar')); $request = (new ServerRequest())->withAttribute('shortCode', $shortCode)->withAttribute(ApiKey::class, $apiKey); $response = $this->action->handle($request);