apiKeyService = $this->createMock(ApiKeyServiceInterface::class); $this->commandTester = CliTestUtils::testerForCommand(new RenameApiKeyCommand($this->apiKeyService)); } #[Test] public function oldNameIsRequestedIfNotProvided(): void { $oldName = 'old name'; $newName = 'new name'; $this->apiKeyService->expects($this->once())->method('listKeys')->willReturn([ ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'foo')), ApiKey::fromMeta(ApiKeyMeta::fromParams(name: $oldName)), ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'bar')), ]); $this->apiKeyService->expects($this->once())->method('renameApiKey')->with( Renaming::fromNames($oldName, $newName), ); $this->commandTester->setInputs([$oldName]); $this->commandTester->execute([ 'new-name' => $newName, ]); } #[Test] public function newNameIsRequestedIfNotProvided(): void { $oldName = 'old name'; $newName = 'new name'; $this->apiKeyService->expects($this->never())->method('listKeys'); $this->apiKeyService->expects($this->once())->method('renameApiKey')->with( Renaming::fromNames($oldName, $newName), ); $this->commandTester->setInputs([$newName]); $this->commandTester->execute([ 'old-name' => $oldName, ]); } #[Test] public function apiIsRenamedWithProvidedNames(): void { $oldName = 'old name'; $newName = 'new name'; $this->apiKeyService->expects($this->never())->method('listKeys'); $this->apiKeyService->expects($this->once())->method('renameApiKey')->with( Renaming::fromNames($oldName, $newName), ); $this->commandTester->execute([ 'old-name' => $oldName, 'new-name' => $newName, ]); } }