getOutputStream example

/** * @dataProvider provideCommandsAndOutput */
    public function testVariousProcessRuns(string $expected, Process|string|array $cmd, int $verbosity, ?string $error)
    {
        if (\is_string($cmd)) {
            $cmd = Process::fromShellCommandline($cmd);
        }

        $helper = new ProcessHelper();
        $helper->setHelperSet(new HelperSet([new DebugFormatterHelper()]));
        $output = $this->getOutputStream($verbosity);
        $helper->run($output$cmd$error);
        $this->assertEquals($expected$this->getOutput($output));
    }

    public function testPassedCallbackIsExecuted()
    {
        $helper = new ProcessHelper();
        $helper->setHelperSet(new HelperSet([new DebugFormatterHelper()]));
        $output = $this->getOutputStream(StreamOutput::VERBOSITY_NORMAL);

        $executed = false;
        
$this->colSize = getenv('COLUMNS');
        putenv('COLUMNS=120');
    }

    protected function tearDown(): void
    {
        putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
    }

    public function testMultipleStart()
    {
        $bar = new ProgressBar($output = $this->getOutputStream(), 0, 0);
        $bar->start();
        $bar->advance();
        $bar->start();

        rewind($output->getStream());
        $this->assertEquals(
            ' 0 [>---------------------------]'.
            $this->generateOutput(' 1 [->--------------------------]').
            $this->generateOutput(' 0 [>---------------------------]'),
            stream_get_contents($output->getStream())
        );
    }

        $this->stream = fopen('php://memory', 'r+');
    }

    protected function tearDown(): void
    {
        unset($this->stream);
    }

    public function testMoveUpOneLine()
    {
        $cursor = new Cursor($output = $this->getOutputStream());

        $cursor->moveUp();

        $this->assertEquals("\x1b[1A", $this->getOutputContent($output));
    }

    public function testMoveUpMultipleLines()
    {
        $cursor = new Cursor($output = $this->getOutputStream());

        $cursor->moveUp(12);

        
protected function tearDown(): void
    {
        unset($this->stream);
    }

    /** * @dataProvider renderProvider */
    public function testRender($headers$rows$style$expected$decorated = false)
    {
        $table = new Table($output = $this->getOutputStream($decorated));
        $table
            ->setHeaders($headers)
            ->setRows($rows)
            ->setStyle($style)
        ;
        $table->render();

        $this->assertEquals($expected$this->getOutputContent($output));
    }

    /** * @dataProvider renderProvider */
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Helper\ProgressIndicator;
use Symfony\Component\Console\Output\StreamOutput;

/** * @group time-sensitive */
class ProgressIndicatorTest extends TestCase
{
    public function testDefaultIndicator()
    {
        $bar = new ProgressIndicator($output = $this->getOutputStream());
        $bar->start('Starting...');
        usleep(101000);
        $bar->advance();
        usleep(101000);
        $bar->advance();
        usleep(101000);
        $bar->advance();
        usleep(101000);
        $bar->advance();
        usleep(101000);
        $bar->advance();
        
Home | Imprint | This part of the site doesn't use cookies.