From 59de5a5f551a6ae41195c2adab3698c05c003b17 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2022 13:53:45 +0200 Subject: [PATCH] Migrated RenameTagCommandTest to use PHPUnit mocks --- .../test/Command/Tag/RenameTagCommandTest.php | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/module/CLI/test/Command/Tag/RenameTagCommandTest.php b/module/CLI/test/Command/Tag/RenameTagCommandTest.php index 9de8d154..a3429e40 100644 --- a/module/CLI/test/Command/Tag/RenameTagCommandTest.php +++ b/module/CLI/test/Command/Tag/RenameTagCommandTest.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\RenameTagCommand; use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Tag\Entity\Tag; @@ -19,12 +19,12 @@ class RenameTagCommandTest 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 RenameTagCommand($this->tagService->reveal())); + $this->tagService = $this->createMock(TagServiceInterface::class); + $this->commandTester = $this->testerForCommand(new RenameTagCommand($this->tagService)); } /** @test */ @@ -32,9 +32,9 @@ class RenameTagCommandTest extends TestCase { $oldName = 'foo'; $newName = 'bar'; - $renameTag = $this->tagService->renameTag(TagRenaming::fromNames($oldName, $newName))->willThrow( - TagNotFoundException::fromTag('foo'), - ); + $this->tagService->expects($this->once())->method('renameTag')->with( + $this->equalTo(TagRenaming::fromNames($oldName, $newName)), + )->willThrowException(TagNotFoundException::fromTag('foo')); $this->commandTester->execute([ 'oldName' => $oldName, @@ -43,7 +43,6 @@ class RenameTagCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString('Tag with name "foo" could not be found', $output); - $renameTag->shouldHaveBeenCalled(); } /** @test */ @@ -51,9 +50,9 @@ class RenameTagCommandTest extends TestCase { $oldName = 'foo'; $newName = 'bar'; - $renameTag = $this->tagService->renameTag(TagRenaming::fromNames($oldName, $newName))->willReturn( - new Tag($newName), - ); + $this->tagService->expects($this->once())->method('renameTag')->with( + $this->equalTo(TagRenaming::fromNames($oldName, $newName)), + )->willReturn(new Tag($newName)); $this->commandTester->execute([ 'oldName' => $oldName, @@ -62,6 +61,5 @@ class RenameTagCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString('Tag properly renamed', $output); - $renameTag->shouldHaveBeenCalled(); } }