ConsoleSectionOutput example

' 0/50 [>---------------------------] 0%'.
            $this->generateOutput(' 1/50 [>---------------------------] 2%').
            $this->generateOutput(' 2/50 [=>--------------------------]'),
            stream_get_contents($output->getStream())
        );
    }

    public function testOverwriteWithSectionOutput()
    {
        $sections = [];
        $stream = $this->getOutputStream(true);
        $output = new ConsoleSectionOutput($stream->getStream()$sections$stream->getVerbosity()$stream->isDecorated()new OutputFormatter());

        $bar = new ProgressBar($output, 50, 0);
        $bar->start();
        $bar->display();
        $bar->advance();
        $bar->advance();

        rewind($output->getStream());
        $this->assertEquals(
            ' 0/50 [>---------------------------] 0%'.\PHP_EOL.
            "\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.\PHP_EOL.
            
$this->stream = fopen('php://memory', 'r+', false);
    }

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

    public function testClearAll()
    {
        $sections = [];
        $output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());

        $output->writeln('Foo'.\PHP_EOL.'Bar');
        $output->clear();

        rewind($output->getStream());
        $this->assertEquals('Foo'.\PHP_EOL.'Bar'.\PHP_EOL.sprintf("\x1b[%dA", 2)."\x1b[0J", stream_get_contents($output->getStream()));
    }

    public function testClearNumberOfLines()
    {
        $sections = [];
        
if (null === $decorated) {
            $this->setDecorated($actualDecorated && $this->stderr->isDecorated());
        }
    }

    /** * Creates a new output section. */
    public function section(): ConsoleSectionOutput
    {
        return new ConsoleSectionOutput($this->getStream()$this->consoleSectionOutputs, $this->getVerbosity()$this->isDecorated()$this->getFormatter());
    }

    /** * @return void */
    public function setDecorated(bool $decorated)
    {
        parent::setDecorated($decorated);
        $this->stderr->setDecorated($decorated);
    }

    
if (null === $decorated) {
            $this->setDecorated($actualDecorated && $this->stderr->isDecorated());
        }
    }

    /** * Creates a new output section. */
    public function section(): ConsoleSectionOutput
    {
        return new ConsoleSectionOutput($this->getStream()$this->consoleSectionOutputs, $this->getVerbosity()$this->isDecorated()$this->getFormatter());
    }

    /** * @return void */
    public function setDecorated(bool $decorated)
    {
        parent::setDecorated($decorated);
        $this->stderr->setDecorated($decorated);
    }

    
TABLE;

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

    public function testSectionOutput()
    {
        $sections = [];
        $stream = $this->getOutputStream(true);
        $output = new ConsoleSectionOutput($stream->getStream()$sections$stream->getVerbosity()$stream->isDecorated()new OutputFormatter());
        $table = new Table($output);
        $table
            ->setHeaders(['ISBN', 'Title', 'Author', 'Price'])
            ->setRows([
                ['99921-58-10-7', 'Divine Comedy', 'Dante Alighieri', '9.95'],
            ]);

        $table->render();

        $table->appendRow(['9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25']);

        
$this->assertSame(0, memory_get_usage() - $start);
    }

    public function testAskAndClearExpectFullSectionCleared()
    {
        $answer = 'Answer';
        $inputStream = fopen('php://memory', 'r+');
        fwrite($inputStream$answer.\PHP_EOL);
        rewind($inputStream);
        $input = $this->createMock(Input::class);
        $sections = [];
        $output = new ConsoleSectionOutput(fopen('php://memory', 'r+', false)$sections, StreamOutput::VERBOSITY_NORMAL, true, new OutputFormatter());
        $input
            ->method('isInteractive')
            ->willReturn(true);
        $input
            ->method('getStream')
            ->willReturn($inputStream);

        $style = new SymfonyStyle($input$output);

        $style->writeln('start');
        $style->write('foo');
        
Home | Imprint | This part of the site doesn't use cookies.