File: BufferIOTest.php

package info (click to toggle)
composer 2.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,528 kB
  • sloc: php: 83,030; makefile: 59; xml: 39
file content (44 lines) | stat: -rw-r--r-- 1,360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php declare(strict_types=1);

/*
 * 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
{
    public function testSetUserInputs(): void
    {
        $bufferIO = new BufferIO();

        $refl = new \ReflectionProperty($bufferIO, 'input');
        (\PHP_VERSION_ID < 80100) and $refl->setAccessible(true);
        $input = $refl->getValue($bufferIO);

        if (!$input instanceof StreamableInputInterface) {
            self::expectException('\RuntimeException');
            self::expectExceptionMessage('Setting the user inputs requires at least the version 3.2 of the symfony/console component.');
        }

        $bufferIO->setUserInputs([
            'yes',
            'no',
            '',
        ]);

        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'));
    }
}