You are here

public function LegacyDialogHelperTest::testSelect in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Tests/Helper/LegacyDialogHelperTest.php \Symfony\Component\Console\Tests\Helper\LegacyDialogHelperTest::testSelect()

File

vendor/symfony/console/Tests/Helper/LegacyDialogHelperTest.php, line 25

Class

LegacyDialogHelperTest
@group legacy

Namespace

Symfony\Component\Console\Tests\Helper

Code

public function testSelect() {
  $dialog = new DialogHelper();
  $helperSet = new HelperSet(array(
    new FormatterHelper(),
  ));
  $dialog
    ->setHelperSet($helperSet);
  $heroes = array(
    'Superman',
    'Batman',
    'Spiderman',
  );
  $dialog
    ->setInputStream($this
    ->getInputStream("\n1\n  1  \nFabien\n1\nFabien\n1\n0,2\n 0 , 2  \n\n\n"));
  $this
    ->assertEquals('2', $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, '2'));
  $this
    ->assertEquals('1', $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes));
  $this
    ->assertEquals('1', $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes));
  $this
    ->assertEquals('1', $dialog
    ->select($output = $this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', false));
  rewind($output
    ->getStream());
  $this
    ->assertContains('Input "Fabien" is not a superhero!', stream_get_contents($output
    ->getStream()));
  try {
    $this
      ->assertEquals('1', $dialog
      ->select($output = $this
      ->getOutputStream(), 'What is your favorite superhero?', $heroes, null, 1));
    $this
      ->fail();
  } catch (\InvalidArgumentException $e) {
    $this
      ->assertEquals('Value "Fabien" is invalid', $e
      ->getMessage());
  }
  $this
    ->assertEquals(array(
    '1',
  ), $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true));
  $this
    ->assertEquals(array(
    '0',
    '2',
  ), $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true));
  $this
    ->assertEquals(array(
    '0',
    '2',
  ), $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true));
  $this
    ->assertEquals(array(
    '0',
    '1',
  ), $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, '0,1', false, 'Input "%s" is not a superhero!', true));
  $this
    ->assertEquals(array(
    '0',
    '1',
  ), $dialog
    ->select($this
    ->getOutputStream(), 'What is your favorite superhero?', $heroes, ' 0 , 1 ', false, 'Input "%s" is not a superhero!', true));
}