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