public function testOptions() { $style = new OutputFormatterStyle(); $style->setOptions(array('reverse', 'conceal')); $this->assertEquals("[7;8mfoo[0m", $style->apply('foo')); $style->setOption('bold'); $this->assertEquals("[7;8;1mfoo[0m", $style->apply('foo')); $style->unsetOption('reverse'); $this->assertEquals("[8;1mfoo[0m", $style->apply('foo')); $style->setOption('bold'); $this->assertEquals("[8;1mfoo[0m", $style->apply('foo')); $style->setOptions(array('bold')); $this->assertEquals("[1mfoo[0m", $style->apply('foo')); try { $style->setOption('foo'); $this->fail('->setOption() throws an \\InvalidArgumentException when the option does not exist in the available options'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->setOption() throws an \\InvalidArgumentException when the option does not exist in the available options'); $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \\InvalidArgumentException when the option does not exist in the available options'); } try { $style->unsetOption('foo'); $this->fail('->unsetOption() throws an \\InvalidArgumentException when the option does not exist in the available options'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->unsetOption() throws an \\InvalidArgumentException when the option does not exist in the available options'); $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \\InvalidArgumentException when the option does not exist in the available options'); } }
public function testOptions() { $style = new OutputFormatterStyle(); $style->setOptions(array('reverse', 'conceal')); $this->assertEquals("[7;8mfoo[0m", $style->apply('foo')); $style->setOption('bold'); $this->assertEquals("[7;8;1mfoo[0m", $style->apply('foo')); $style->unsetOption('reverse'); $this->assertEquals("[8;1mfoo[0m", $style->apply('foo')); $style->setOption('bold'); $this->assertEquals("[8;1mfoo[0m", $style->apply('foo')); $style->setOptions(array('bold')); $this->assertEquals("[1mfoo[0m", $style->apply('foo')); }
/** * Applies the style to a given text. * * @param string $text The text to style * * @return string * * @codeCoverageIgnore - nothing to test. */ public function apply($text) { return $this->symfony->apply($text); }
/** * Applies the style to a given text. * * @param string $text The text to style * * @return string */ public function apply($text) { $ret = $text; // ################## // Padding // ################## if (!empty($this->padding)) { $ret = $this->padding . $ret; } // ################## // Wrap // ################## if (!empty($this->wrap)) { list($width) = $this->application->getTerminalDimensions(); $length = strlen($text); $wrapLength = (int) ($width - $length - 2) / 2 * 0.5; if ($wrapLength >= 1) { $ret = str_repeat($this->wrap, $wrapLength) . ' ' . $ret . ' ' . str_repeat($this->wrap, $wrapLength); } } $ret = parent::apply($ret); // ################## // Padding // ################## if (!empty($this->paddingOutside)) { $ret = $this->paddingOutside . $ret; } return $ret; }
public function __toString() { if (!$this->getIconHandler()->getRuntimeConfig()->hasUnicodeIconSupport()) { return ''; } $colour = null; $backgroundColour = null; $options = array(); if (!is_null($this->data['colour'])) { $colour = $this->data['colour']; } if (!is_null($this->data['bgColour'])) { $backgroundColour = $this->data['bgColour']; } if (!empty($this->data['options'])) { $options = $this->data['options']; } $style = new OutputFormatterStyle($colour, $backgroundColour, $options); $output = $style->apply($this->data['icon']); return $output; }