From 2d168565820b5d925e23dc4d21e5b16a780328d0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2022 13:45:11 +0200 Subject: [PATCH] Migrated DeleteTagsCommandTest to use PHPUnit mocks --- .../CLI/test/Command/Tag/DeleteTagsCommandTest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php index b03bf1ee..fbaa248f 100644 --- a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Tag; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Tag\DeleteTagsCommand; use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; @@ -16,12 +16,12 @@ class DeleteTagsCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private ObjectProphecy $tagService; + private MockObject $tagService; protected function setUp(): void { - $this->tagService = $this->prophesize(TagServiceInterface::class); - $this->commandTester = $this->testerForCommand(new DeleteTagsCommand($this->tagService->reveal())); + $this->tagService = $this->createMock(TagServiceInterface::class); + $this->commandTester = $this->testerForCommand(new DeleteTagsCommand($this->tagService)); } /** @test */ @@ -37,8 +37,7 @@ class DeleteTagsCommandTest extends TestCase public function serviceIsInvokedOnSuccess(): void { $tagNames = ['foo', 'bar']; - $deleteTags = $this->tagService->deleteTags($tagNames)->will(function (): void { - }); + $this->tagService->expects($this->once())->method('deleteTags')->with($this->equalTo($tagNames)); $this->commandTester->execute([ '--name' => $tagNames, @@ -46,6 +45,5 @@ class DeleteTagsCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString('Tags properly deleted', $output); - $deleteTags->shouldHaveBeenCalled(); } }