apiKeyService = $this->createMock(ApiKeyServiceInterface::class); $this->commandTester = CliTestUtils::testerForCommand(new DisableKeyCommand($this->apiKeyService)); } #[Test] public function providedApiKeyIsDisabled(): void { $apiKey = 'abcd1234'; $this->apiKeyService->expects($this->once())->method('disable')->with($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($apiKey)->willThrowException( new InvalidArgumentException($expectedMessage), ); $this->commandTester->execute([ 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); self::assertStringContainsString($expectedMessage, $output); } }