From 9ac6a50e66c3576d4fbe202d576a04973d30c89b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 22:16:19 +0200 Subject: [PATCH] Migrated SingleStepCreateShortUrlActionTest to use PHPUnit mocks --- .../SingleStepCreateShortUrlActionTest.php | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index 3fd29c2f..5e0867e7 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.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\Common\Rest\DataTransformerInterface; use Shlinkio\Shlink\Core\Options\UrlShortenerOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; @@ -19,21 +17,18 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class SingleStepCreateShortUrlActionTest extends TestCase { - use ProphecyTrait; - private SingleStepCreateShortUrlAction $action; - private ObjectProphecy $urlShortener; - private ObjectProphecy $transformer; + private MockObject $urlShortener; protected function setUp(): void { - $this->urlShortener = $this->prophesize(UrlShortenerInterface::class); - $this->transformer = $this->prophesize(DataTransformerInterface::class); - $this->transformer->transform(Argument::type(ShortUrl::class))->willReturn([]); + $this->urlShortener = $this->createMock(UrlShortenerInterface::class); + $transformer = $this->createMock(DataTransformerInterface::class); + $transformer->method('transform')->willReturn([]); $this->action = new SingleStepCreateShortUrlAction( - $this->urlShortener->reveal(), - $this->transformer->reveal(), + $this->urlShortener, + $transformer, new UrlShortenerOptions(), ); } @@ -46,13 +41,12 @@ class SingleStepCreateShortUrlActionTest extends TestCase $request = (new ServerRequest())->withQueryParams([ 'longUrl' => 'http://foobar.com', ])->withAttribute(ApiKey::class, $apiKey); - $generateShortCode = $this->urlShortener->shorten( + $this->urlShortener->expects($this->once())->method('shorten')->with( ShortUrlCreation::fromRawData(['apiKey' => $apiKey, 'longUrl' => 'http://foobar.com']), )->willReturn(ShortUrl::createEmpty()); $resp = $this->action->handle($request); self::assertEquals(200, $resp->getStatusCode()); - $generateShortCode->shouldHaveBeenCalled(); } }