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')); }
/** * {@inheritdoc} */ public function createOutput($stream = null) { $stream = $stream ?: $this->createOutputStream(); $format = $this->createOutputFormatter(); // set user-defined styles foreach ($this->getOutputStyles() as $name => $options) { $style = new OutputFormatterStyle(); if (isset($options[0])) { $style->setForeground($options[0]); } if (isset($options[1])) { $style->setBackground($options[1]); } if (isset($options[2])) { $style->setOptions($options[2]); } $format->setStyle($name, $style); } $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, $this->isOutputDecorated(), $format); $this->configureOutputStream($output); return $output; }
/** * Returns new output console. * * @return StreamOutput * * @uses createOutputStream() */ protected function createOutputConsole() { $stream = $this->createOutputStream(); $format = new OutputFormatter(); // set user-defined styles foreach ($this->parameters->get('output_styles') as $name => $options) { $style = new OutputFormatterStyle(); if (isset($options[0])) { $style->setForeground($options[0]); } if (isset($options[1])) { $style->setBackground($options[1]); } if (isset($options[2])) { $style->setOptions($options[2]); } $format->setStyle($name, $style); } return new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, $this->parameters->get('output_decorate'), $format); }
/** * Sets multiple options * * @author Art <*****@*****.**> * * @param array $opt The options * * @codeCoverageIgnore - nothing to test. */ public function setOptions(array $opt) { $this->symfony->setOptions($opt); }