2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-01-03 09:35:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\IO;
|
|
|
|
|
|
|
|
use Composer\IO\BufferIO;
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
use Symfony\Component\Console\Input\StreamableInputInterface;
|
|
|
|
|
|
|
|
class BufferIOTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSetUserInputs(): void
|
2019-01-03 09:35:51 +00:00
|
|
|
{
|
|
|
|
$bufferIO = new BufferIO();
|
|
|
|
|
|
|
|
$refl = new \ReflectionProperty($bufferIO, 'input');
|
|
|
|
$refl->setAccessible(true);
|
|
|
|
$input = $refl->getValue($bufferIO);
|
|
|
|
|
|
|
|
if (!$input instanceof StreamableInputInterface) {
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException('\RuntimeException');
|
|
|
|
self::expectExceptionMessage('Setting the user inputs requires at least the version 3.2 of the symfony/console component.');
|
2019-01-03 09:35:51 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$bufferIO->setUserInputs([
|
2019-01-03 09:35:51 +00:00
|
|
|
'yes',
|
|
|
|
'no',
|
|
|
|
'',
|
2022-08-17 12:20:07 +00:00
|
|
|
]);
|
2019-01-03 09:35:51 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertTrue($bufferIO->askConfirmation('Please say yes!', false));
|
|
|
|
self::assertFalse($bufferIO->askConfirmation('Now please say no!', true));
|
|
|
|
self::assertSame('default', $bufferIO->ask('Empty string last', 'default'));
|
2019-01-03 09:35:51 +00:00
|
|
|
}
|
|
|
|
}
|