apiKeyService = $this->createMock(ApiKeyServiceInterface::class); $this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService)); } /** @test */ public function providedApiKeyIsDisabled(): void { $apiKey = 'abcd1234'; $this->apiKeyService->expects($this->once())->method('disable')->with($this->equalTo($apiKey)); $this->commandTester->execute([ 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); self::assertStringContainsString('API key "abcd1234" properly disabled', $output); } /** @test */ public function errorIsReturnedIfServiceThrowsException(): void { $apiKey = 'abcd1234'; $expectedMessage = 'API key "abcd1234" does not exist.'; $this->apiKeyService->expects($this->once())->method('disable')->with( $this->equalTo($apiKey), )->willThrowException(new InvalidArgumentException($expectedMessage)); $this->commandTester->execute([ 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); self::assertStringContainsString($expectedMessage, $output); } }