public function testWithFreeUsername() { $username = '******'; $this->userRepository->expects($this->at(0))->method('findUserByName')->with($username)->will($this->returnValue(false)); $this->randomStringGenerator->expects($this->at(0))->method('generate')->will($this->returnValue('taken1')); $this->randomStringGenerator->expects($this->at(1))->method('generate')->will($this->returnValue('taken2')); $this->randomStringGenerator->expects($this->at(2))->method('generate')->will($this->returnValue('freeKey')); $this->userRepository->expects($this->at(1))->method('findUserByKey')->with('taken1')->will($this->returnValue(array('user' => 'peter'))); $this->userRepository->expects($this->at(2))->method('findUserByKey')->with('taken2')->will($this->returnValue(array('user' => 'peter2'))); $this->userRepository->expects($this->at(3))->method('findUserByKey')->with('freeKey')->will($this->returnValue(false)); $this->userRepository->expects($this->at(4))->method('addUser')->with('free', 'freeKey'); $key = $this->object->generate($username); $this->assertEquals('freeKey', $key); }
/** * @param InputInterface $input * @param OutputInterface $output * @throws \Exception */ protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->apiKeyGenerator) { throw new \Exception('ApiKeyGenerator is not set!'); } $name = $input->getArgument('name'); if (!$name) { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $question = new Question('<question>Username?</question> '); $name = $helper->ask($input, $output, $question); } $key = $this->apiKeyGenerator->generate($name); $output->writeln(sprintf('<info>User "%s" succesfully created</info>', $name)); $output->writeln(sprintf('<info>API-Key: %s</info>', $key)); }