From 2b7b5e9a8f237adcd12f4537afd80a86e8d93916 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 22 Oct 2022 12:48:17 +0200 Subject: [PATCH] Migrated DisableKeyCommandTest to use PHPUnit mocks --- .../test/Command/Api/DisableKeyCommandTest.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index 41a4f982..78f5bfa6 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Api; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; @@ -17,19 +17,19 @@ class DisableKeyCommandTest extends TestCase use CliTestUtilsTrait; private CommandTester $commandTester; - private ObjectProphecy $apiKeyService; + private MockObject $apiKeyService; protected function setUp(): void { - $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); - $this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService->reveal())); + $this->apiKeyService = $this->createMock(ApiKeyServiceInterface::class); + $this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService)); } /** @test */ public function providedApiKeyIsDisabled(): void { $apiKey = 'abcd1234'; - $this->apiKeyService->disable($apiKey)->shouldBeCalledOnce(); + $this->apiKeyService->expects($this->once())->method('disable')->with($this->equalTo($apiKey)); $this->commandTester->execute([ 'apiKey' => $apiKey, @@ -44,7 +44,9 @@ class DisableKeyCommandTest extends TestCase { $apiKey = 'abcd1234'; $expectedMessage = 'API key "abcd1234" does not exist.'; - $disable = $this->apiKeyService->disable($apiKey)->willThrow(new InvalidArgumentException($expectedMessage)); + $this->apiKeyService->expects($this->once())->method('disable')->with( + $this->equalTo($apiKey), + )->willThrowException(new InvalidArgumentException($expectedMessage)); $this->commandTester->execute([ 'apiKey' => $apiKey, @@ -52,6 +54,5 @@ class DisableKeyCommandTest extends TestCase $output = $this->commandTester->getDisplay(); self::assertStringContainsString($expectedMessage, $output); - $disable->shouldHaveBeenCalledOnce(); } }