当前位置: 首页>>代码示例>>PHP>>正文


PHP QuestionHelper::setInputStream方法代码示例

本文整理汇总了PHP中Symfony\Component\Console\Helper\QuestionHelper::setInputStream方法的典型用法代码示例。如果您正苦于以下问题:PHP QuestionHelper::setInputStream方法的具体用法?PHP QuestionHelper::setInputStream怎么用?PHP QuestionHelper::setInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Console\Helper\QuestionHelper的用法示例。


在下文中一共展示了QuestionHelper::setInputStream方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCanExecute

 public function testCanExecute()
 {
     if (!class_exists('Symfony\\Component\\Console\\Helper\\QuestionHelper')) {
         $this->markTestSkipped('The QuestionHelper must be available.');
     }
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->setConstructorArgs(array(array()))->setMethods(array('isInteractive'))->getMock();
     $input->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $output = $this->getOutputStream();
     $class = new \ReflectionClass('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand');
     $method = $class->getMethod('canExecute');
     $method->setAccessible(true);
     /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */
     $command = $this->getMock('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', array('getHelperSet'));
     $helper = new QuestionHelper();
     $helper->setInputStream($this->getInputStream("y\n"));
     if ($helper instanceof QuestionHelper) {
         $helperSet = new HelperSet(array('question' => $helper));
     }
     $command->setHelperSet($helperSet);
     $command->expects($this->any())->method('getHelperSet')->will($this->returnValue($helperSet));
     //should return true if user confirm
     $this->assertEquals(true, $method->invokeArgs($command, array('test', $input, $output)));
     //shoudl return false if user cancel
     $helper->setInputStream($this->getInputStream("n\n"));
     $this->assertEquals(false, $method->invokeArgs($command, array('test', $input, $output)));
     //should return true if non interactive
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->setConstructorArgs(array(array()))->setMethods(array('isInteractive'))->getMock();
     $input->expects($this->any())->method('isInteractive')->will($this->returnValue(false));
     $this->assertEquals(true, $method->invokeArgs($command, array('test', $input, $output)));
 }
开发者ID:comporu,项目名称:migrations,代码行数:30,代码来源:MigrateCommandTest.php

示例2: ifTagsFlagIsProvidedTagsColumnIsIncluded

 /**
  * @test
  */
 public function ifTagsFlagIsProvidedTagsColumnIsIncluded()
 {
     $this->questionHelper->setInputStream($this->getInputStream('\\n'));
     $this->shortUrlService->listShortUrls(1, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))->shouldBeCalledTimes(1);
     $this->commandTester->execute(['command' => 'shortcode:list', '--showTags' => true]);
     $output = $this->commandTester->getDisplay();
     $this->assertTrue(strpos($output, 'Tags') > 0);
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:11,代码来源:ListShortcodesCommandTest.php

示例3: iExecuteCommandAndConfirm

 /**
  * @param string $name
  */
 private function iExecuteCommandAndConfirm($name)
 {
     $this->questionHelper = $this->command->getHelper('question');
     $inputString = 'y' . PHP_EOL;
     $this->questionHelper->setInputStream($this->getInputStream($inputString));
     try {
         $this->tester->execute(['command' => $name]);
     } catch (\Exception $e) {
     }
 }
开发者ID:sylius,项目名称:sylius,代码行数:13,代码来源:InstallerContext.php

示例4: execute

 public function execute()
 {
     $this->tester = new CommandTester($this->command);
     if ('' !== $this->inputStream) {
         if ($this->command->getHelperSet()) {
             $helper = $this->command->getHelper('question');
         } else {
             $this->command->setHelperSet(new HelperSet([$helper = new QuestionHelper()]));
         }
         $helper->setInputStream($this->getInputStream($this->inputStream));
     }
     $this->tester->execute(array_merge($this->options, $this->arguments), ['decorated' => false]);
     return $this;
 }
开发者ID:wouterj,项目名称:eloquent-bundle,代码行数:14,代码来源:TestCommand.php

示例5: testAmbiguousChoiceFromChoicelist

 /**
  * @expectedException        \InvalidArgumentException
  * @expectedExceptionMessage The provided answer is ambiguous. Value should be one of env_2 or env_3.
  */
 public function testAmbiguousChoiceFromChoicelist()
 {
     $possibleChoices = array('env_1' => 'My first environment', 'env_2' => 'My environment', 'env_3' => 'My environment');
     $dialog = new QuestionHelper();
     $dialog->setInputStream($this->getInputStream("My environment\n"));
     $helperSet = new HelperSet(array(new FormatterHelper()));
     $dialog->setHelperSet($helperSet);
     $question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
     $question->setMaxAttempts(1);
     $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
 }
开发者ID:saj696,项目名称:pipe,代码行数:15,代码来源:QuestionHelperTest.php

示例6: testAskAndValidate

 public function testAskAndValidate()
 {
     $dialog = new QuestionHelper();
     $helperSet = new HelperSet(array(new FormatterHelper()));
     $dialog->setHelperSet($helperSet);
     $error = 'This is not a color!';
     $validator = function ($color) use($error) {
         if (!in_array($color, array('white', 'black'))) {
             throw new \InvalidArgumentException($error);
         }
         return $color;
     };
     $question = new Question('What color was the white horse of Henry IV?', 'white');
     $question->setValidator($validator);
     $question->setMaxAttempts(2);
     $dialog->setInputStream($this->getInputStream("\nblack\n"));
     $this->assertEquals('white', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
     $this->assertEquals('black', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
     $dialog->setInputStream($this->getInputStream("green\nyellow\norange\n"));
     try {
         $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
         $this->fail();
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals($error, $e->getMessage());
     }
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:26,代码来源:QuestionHelperTest.php

示例7: testChoiceOutputFormattingQuestionForUtf8Keys

 /**
  * @requires function mb_strwidth
  */
 public function testChoiceOutputFormattingQuestionForUtf8Keys()
 {
     $question = 'Lorem ipsum?';
     $possibleChoices = array('foo' => 'foo', 'żółw' => 'bar', 'łabądź' => 'baz');
     $outputShown = array($question, '  [<info>foo   </info>] foo', '  [<info>żółw  </info>] bar', '  [<info>łabądź</info>] baz');
     $output = $this->getMock('\\Symfony\\Component\\Console\\Output\\OutputInterface');
     $output->method('getFormatter')->willReturn(new OutputFormatter());
     $dialog = new QuestionHelper();
     $dialog->setInputStream($this->getInputStream("\n"));
     $helperSet = new HelperSet(array(new FormatterHelper()));
     $dialog->setHelperSet($helperSet);
     $output->expects($this->once())->method('writeln')->with($this->equalTo($outputShown));
     $question = new ChoiceQuestion($question, $possibleChoices, 'foo');
     $dialog->ask($this->createInputInterfaceMock(), $output, $question);
 }
开发者ID:cilefen,项目名称:symfony,代码行数:18,代码来源:QuestionHelperTest.php

示例8: getHelperSet

 protected function getHelperSet($input = "")
 {
     $question = new QuestionHelper();
     $question->setInputStream($this->getInputStream($input));
     return new HelperSet(array(new FormatterHelper(), $question));
 }
开发者ID:fuzzyma,项目名称:contao-database-commands-bundle,代码行数:6,代码来源:CommandTest.php

示例9: testAmbiguousChoiceFromChoicelist

 public function testAmbiguousChoiceFromChoicelist()
 {
     $possibleChoices = array('env_1' => 'My environment 1', 'env_2' => 'My environment', 'env_3' => 'My environment');
     $dialog = new QuestionHelper();
     $dialog->setInputStream($this->getInputStream("My environment\n"));
     $helperSet = new HelperSet(array(new FormatterHelper()));
     $dialog->setHelperSet($helperSet);
     $question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
     try {
         $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals('The provided answer is ambiguous. Value should be one of env_2 or env_3.', $e->getMessage());
     }
 }
开发者ID:chiroro-vietnam,项目名称:asahi,代码行数:14,代码来源:QuestionHelperTest.php

示例10: testAskThrowsExceptionOnMissingInputWithValidator

 /**
  * @expectedException        \Symfony\Component\Console\Exception\RuntimeException
  * @expectedExceptionMessage Aborted
  */
 public function testAskThrowsExceptionOnMissingInputWithValidator()
 {
     $dialog = new QuestionHelper();
     $dialog->setInputStream($this->getInputStream(''));
     $question = new Question('What\'s your name?');
     $question->setValidator(function () {
         if (!$value) {
             throw new \Exception('A value is required.');
         }
     });
     $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
 }
开发者ID:shegun-babs,项目名称:dakrush,代码行数:16,代码来源:QuestionHelperTest.php


注:本文中的Symfony\Component\Console\Helper\QuestionHelper::setInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。