setForeground example

if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string$matches, \PREG_SET_ORDER)) {
            return null;
        }

        $style = new OutputFormatterStyle();
        foreach ($matches as $match) {
            array_shift($match);
            $match[0] = strtolower($match[0]);

            if ('fg' == $match[0]) {
                $style->setForeground(strtolower($match[1]));
            } elseif ('bg' == $match[0]) {
                $style->setBackground(strtolower($match[1]));
            } elseif ('href' === $match[0]) {
                $url = preg_replace('{\\\\([<>])}', '$1', $match[1]);
                $style->setHref($url);
            } elseif ('options' === $match[0]) {
                preg_match_all('([^,;]+)', strtolower($match[1])$options);
                $options = array_shift($options);
                foreach ($options as $option) {
                    $style->setOption($option);
                }
            }

    public function testApply()
    {
        $style = new NullOutputFormatterStyle();

        $this->assertSame('foo', $style->apply('foo'));
    }

    public function testSetForeground()
    {
        $style = new NullOutputFormatterStyle();
        $style->setForeground('black');
        $this->assertSame('foo', $style->apply('foo'));
    }

    public function testSetBackground()
    {
        $style = new NullOutputFormatterStyle();
        $style->setBackground('blue');
        $this->assertSame('foo', $style->apply('foo'));
    }

    public function testOptions()
    {
if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string$matches, \PREG_SET_ORDER)) {
            return null;
        }

        $style = new OutputFormatterStyle();
        foreach ($matches as $match) {
            array_shift($match);
            $match[0] = strtolower($match[0]);

            if ('fg' == $match[0]) {
                $style->setForeground(strtolower($match[1]));
            } elseif ('bg' == $match[0]) {
                $style->setBackground(strtolower($match[1]));
            } elseif ('href' === $match[0]) {
                $url = preg_replace('{\\\\([<>])}', '$1', $match[1]);
                $style->setHref($url);
            } elseif ('options' === $match[0]) {
                preg_match_all('([^,;]+)', strtolower($match[1])$options);
                $options = array_shift($options);
                foreach ($options as $option) {
                    $style->setOption($option);
                }
            }
$style = new OutputFormatterStyle('red', null, ['blink']);
        $this->assertEquals("\033[31;5mfoo\033[39;25m", $style->apply('foo'));

        $style = new OutputFormatterStyle(null, 'white');
        $this->assertEquals("\033[47mfoo\033[49m", $style->apply('foo'));
    }

    public function testForeground()
    {
        $style = new OutputFormatterStyle();

        $style->setForeground('black');
        $this->assertEquals("\033[30mfoo\033[39m", $style->apply('foo'));

        $style->setForeground('blue');
        $this->assertEquals("\033[34mfoo\033[39m", $style->apply('foo'));

        $style->setForeground('default');
        $this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo'));

        $this->expectException(\InvalidArgumentException::class);
        $style->setForeground('undefined-color');
    }

    
Home | Imprint | This part of the site doesn't use cookies.