diff options
author | Derky <derky@phpbb.com> | 2018-01-05 22:44:34 +0100 |
---|---|---|
committer | Derky <derky@phpbb.com> | 2018-01-05 22:44:34 +0100 |
commit | 182a96f2738316adcb292816a9ac8af0e0cb5866 (patch) | |
tree | 0b6a0fb40a2ea201fdf4cfc5e4cc5ebfb4cb46db /tests/console | |
parent | Merge pull request #5069 from marc1706/ticket/14972-rhea (diff) | |
parent | [ticket/15055] Display appveyor badges in readme (diff) | |
download | phpbb-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.gz phpbb-182a96f2738316adcb292816a9ac8af0e0cb5866.tar.bz2 phpbb-182a96f2738316adcb292816a9ac8af0e0cb5866.zip |
Merge pull request #4680 from marc1706/ticket/15055
[ticket/15055] Add appveyor file to allow running tests on appveyor as well
Diffstat (limited to 'tests/console')
-rw-r--r-- | tests/console/user/add_test.php | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php index 8641bf87b6..bdfb8a8d2a 100644 --- a/tests/console/user/add_test.php +++ b/tests/console/user/add_test.php @@ -14,12 +14,15 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use phpbb\console\command\user\add; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; require_once dirname(__FILE__) . '/base.php'; class phpbb_console_user_add_test extends phpbb_console_user_base { - public function get_command_tester() + public function get_command_tester($question_answers = []) { $application = new Application(); $application->add(new add( @@ -34,7 +37,42 @@ class phpbb_console_user_add_test extends phpbb_console_user_base $command = $application->find('user:add'); $this->command_name = $command->getName(); - $this->question = $command->getHelper('question'); + + if (!empty($question_answers)) + { + $ask = function(InputInterface $input, OutputInterface $output, Question $question) use ($question_answers) + { + $text = $question->getQuestion(); + + // handle a question + foreach ($question_answers as $expected_question => $answer) + { + if (strpos($text, $expected_question) !== false) + { + $response = $answer; + } + } + + if (!isset($response)) + { + throw new \RuntimeException('Was asked for input on an unhandled question: ' . $text); + } + + $output->writeln(print_r($response, true)); + return $response; + }; + $helper = $this->getMock('\Symfony\Component\Console\Helper\QuestionHelper', array('ask')); + $helper->expects($this->any()) + ->method('ask') + ->will($this->returnCallback($ask)); + $this->question = $helper; + $command->getHelperSet()->set($helper, 'question'); + } + else + { + $this->question = $command->getHelper('question'); + } + return new CommandTester($command); } @@ -57,7 +95,11 @@ class phpbb_console_user_add_test extends phpbb_console_user_base public function test_add_dialog() { - $command_tester = $this->get_command_tester(); + $command_tester = $this->get_command_tester([ + 'USERNAME' => 'bar', + 'PASSWORD' => 'password', + 'EMAIL_ADDRESS' => 'bar@test.com', + ]); $this->assertEquals(2, $this->get_user_id('Admin')); |