From d20253858161a7386f4af0298897473546138f97 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 22:10:41 +0200 Subject: [PATCH] Migrated DeleteShortUrlActionTest to use PHPUnit mocks --- .../ShortUrl/DeleteShortUrlActionTest.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index bc073cf6..30a8e647 100644 --- a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -5,39 +5,31 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\ShortUrl; use Laminas\Diactoros\ServerRequestFactory; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction; use Shlinkio\Shlink\Rest\Entity\ApiKey; class DeleteShortUrlActionTest extends TestCase { - use ProphecyTrait; - private DeleteShortUrlAction $action; - private ObjectProphecy $service; + private MockObject $service; protected function setUp(): void { - $this->service = $this->prophesize(DeleteShortUrlServiceInterface::class); - $this->action = new DeleteShortUrlAction($this->service->reveal()); + $this->service = $this->createMock(DeleteShortUrlServiceInterface::class); + $this->action = new DeleteShortUrlAction($this->service); } /** @test */ public function emptyResponseIsReturnedIfProperlyDeleted(): void { $apiKey = ApiKey::create(); - $deleteByShortCode = $this->service->deleteByShortCode(Argument::any(), false, $apiKey)->will( - function (): void { - }, - ); + $this->service->expects($this->once())->method('deleteByShortCode'); $resp = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute(ApiKey::class, $apiKey)); self::assertEquals(204, $resp->getStatusCode()); - $deleteByShortCode->shouldHaveBeenCalledOnce(); } }