В Symfony 2.6 выполняется проверка команды консоли, которая запрашивает пароль, тест никогда не завершается (и никогда не истекает), если ответ настроен на скрытие с помощью $question->setHidden(true);
Комментирование строки позволяет завершить тест с успехом. [То же самое было с DialogHelper и его эквивалентным методом скрытия ответа, а не как показано здесь с помощью QuestionHelper.]
Вышеприведенное описание относится к тестированию команды интерактивной консоли. Тестирование самой команды с помощью теста ниже приводит к RuntimeException: Aborted
в $input->setArgument('username', $helper->ask($input, $output, $question));
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
class CreateUserCommand extends ContainerAwareCommand
{
...
protected function interact(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
$question = new Question('Please enter a password: ');
$question->setValidator(function ($answer) {
if (empty($answer)) {
throw new \RuntimeException(
'A password is required'
);
}
return $answer;
});
$question->setHidden(true);
$question->setMaxAttempts(5);
$input->setArgument('password', $helper->ask($input, $output, $question));
...
}
...
}
public function testExecute()
{
$kernel = $this->createKernel();
$kernel->boot();
$application = new Application($kernel);
$application->add(new CreateUserCommand());
$command = $application->find('truckee:user:create');
$commandTester = new CommandTester($command);
$dialog = $command->getHelper('question');
$dialog->setInputStream($this->getInputStream("bborko\n"
. "Benny\n "
. "Borko\n "
. "[email protected]\n "
. "123Abcd\n "
. "sandbox\n"
));
$commandTester->execute(array('command' => $command->getName()));
$this->assertRegExp('/.../', $commandTester->getDisplay());
}
public function testCreateAdmin()
{
$kernel = $this->createKernel();
$kernel->boot();
$application = new Application($kernel);
$application->add(new CreateUserCommand());
$command = $application->find('truckee:user:create');
$commandTester = new CommandTester($command);
$commandTester->execute(
array(
'username' => 'bborko',
'firstname' => 'Benny',
'lastname' => 'Borko',
'email' => '[email protected]',
'password' => '123Abcd',
'type' => 'admin',
)
);
$this->assertRegExp('/.../', $commandTester->getDisplay());
}
Еще раз я узнаю, что Windows - не лучшее место для развития в Symfony. Сегодня я нашел
$this-> markTestSkipped ("Этот тест не поддерживается в Windows");
в Symfony\Component\Console\Tests\Helper\QuestionHelperTest public function testAskHiddenResponse()
.
Если вы хотите узнать, какие тесты не поддерживаются, найдите текст "Windows" в каталоге vendor\symfony
(например, с IDE, например Netbeans).