BufferIOTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\IO;
  12. use Composer\IO\BufferIO;
  13. use Composer\Test\TestCase;
  14. use Symfony\Component\Console\Input\StreamableInputInterface;
  15. class BufferIOTest extends TestCase
  16. {
  17. public function testSetUserInputs()
  18. {
  19. $bufferIO = new BufferIO();
  20. $refl = new \ReflectionProperty($bufferIO, 'input');
  21. $refl->setAccessible(true);
  22. $input = $refl->getValue($bufferIO);
  23. if (!$input instanceof StreamableInputInterface) {
  24. $this->setExpectedException('\RuntimeException', 'Setting the user inputs requires at least the version 3.2 of the symfony/console component.');
  25. }
  26. $bufferIO->setUserInputs(array(
  27. 'yes',
  28. 'no',
  29. '',
  30. ));
  31. $this->assertTrue($bufferIO->askConfirmation('Please say yes!', 'no'));
  32. $this->assertFalse($bufferIO->askConfirmation('Now please say no!', 'yes'));
  33. $this->assertSame('default', $bufferIO->ask('Empty string last', 'default'));
  34. }
  35. }