apiKeyService = $this->prophesize(ApiKeyService::class); $command = new DisableKeyCommand($this->apiKeyService->reveal()); $app = new Application(); $app->add($command); $this->commandTester = new CommandTester($command); } /** @test */ public function providedApiKeyIsDisabled() { $apiKey = 'abcd1234'; $this->apiKeyService->disable($apiKey)->shouldBeCalledOnce(); $this->commandTester->execute([ 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('API key "abcd1234" properly disabled', $output); } /** @test */ public function errorIsReturnedIfServiceThrowsException() { $apiKey = 'abcd1234'; $disable = $this->apiKeyService->disable($apiKey)->willThrow(InvalidArgumentException::class); $this->commandTester->execute([ 'apiKey' => $apiKey, ]); $output = $this->commandTester->getDisplay(); $this->assertStringContainsString('API key "abcd1234" does not exist.', $output); $disable->shouldHaveBeenCalledOnce(); } }