From ab9ea887d2ef96f097c4253e85be567f743ffd35 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 Oct 2022 22:17:35 +0200 Subject: [PATCH] Migrated DeleteTagsActionTest to use PHPUnit mocks --- .../test/Action/Tag/DeleteTagsActionTest.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php index 457507e8..cca532a4 100644 --- a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php +++ b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php @@ -5,25 +5,21 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Rest\Action\Tag; 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\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction; use Shlinkio\Shlink\Rest\Entity\ApiKey; class DeleteTagsActionTest extends TestCase { - use ProphecyTrait; - private DeleteTagsAction $action; - private ObjectProphecy $tagService; + private MockObject $tagService; protected function setUp(): void { - $this->tagService = $this->prophesize(TagServiceInterface::class); - $this->action = new DeleteTagsAction($this->tagService->reveal()); + $this->tagService = $this->createMock(TagServiceInterface::class); + $this->action = new DeleteTagsAction($this->tagService); } /** @@ -35,12 +31,14 @@ class DeleteTagsActionTest extends TestCase $request = (new ServerRequest()) ->withQueryParams(['tags' => $tags]) ->withAttribute(ApiKey::class, ApiKey::create()); - $deleteTags = $this->tagService->deleteTags($tags ?: [], Argument::type(ApiKey::class)); + $this->tagService->expects($this->once())->method('deleteTags')->with( + $tags ?? [], + $this->isInstanceOf(ApiKey::class), + ); $response = $this->action->handle($request); self::assertEquals(204, $response->getStatusCode()); - $deleteTags->shouldHaveBeenCalled(); } public function provideTags(): iterable