public function testOptions()
 {
     $style = new OutputFormatterStyle();
     $style->setOptions(array('reverse', 'conceal'));
     $this->assertEquals("foo", $style->apply('foo'));
     $style->setOption('bold');
     $this->assertEquals("foo", $style->apply('foo'));
     $style->unsetOption('reverse');
     $this->assertEquals("foo", $style->apply('foo'));
     $style->setOption('bold');
     $this->assertEquals("foo", $style->apply('foo'));
     $style->setOptions(array('bold'));
     $this->assertEquals("foo", $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("foo", $style->apply('foo'));
     $style->setOption('bold');
     $this->assertEquals("foo", $style->apply('foo'));
     $style->unsetOption('reverse');
     $this->assertEquals("foo", $style->apply('foo'));
     $style->setOption('bold');
     $this->assertEquals("foo", $style->apply('foo'));
     $style->setOptions(array('bold'));
     $this->assertEquals("foo", $style->apply('foo'));
 }
Beispiel #3
0
 /**
  * Tries to create new style instance from string.
  *
  * @param string $string        	
  *
  * @return OutputFormatterStyle|bool false if string is not format string
  */
 private function createStyleFromString($string)
 {
     if (isset($this->styles[$string])) {
         return $this->styles[$string];
     }
     if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($string), $matches, PREG_SET_ORDER)) {
         return false;
     }
     $style = new OutputFormatterStyle();
     foreach ($matches as $match) {
         array_shift($match);
         if ('fg' == $match[0]) {
             $style->setForeground($match[1]);
         } elseif ('bg' == $match[0]) {
             $style->setBackground($match[1]);
         } else {
             try {
                 $style->setOption($match[1]);
             } catch (\InvalidArgumentException $e) {
                 return false;
             }
         }
     }
     return $style;
 }
Beispiel #4
0
 /**
  * Tries to create new style instance from string.
  *
  * @param string $string
  *
  * @return OutputFormatterStyle|bool false if string is not format string
  */
 private function createStyleFromString($string)
 {
     if (isset($this->styles[$string])) {
         return $this->styles[$string];
     }
     if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, PREG_SET_ORDER)) {
         return false;
     }
     $style = new OutputFormatterStyle();
     foreach ($matches as $match) {
         array_shift($match);
         if ('fg' == $match[0]) {
             $style->setForeground($match[1]);
         } elseif ('bg' == $match[0]) {
             $style->setBackground($match[1]);
         } elseif ('options' === $match[0]) {
             preg_match_all('([^,;]+)', $match[1], $options);
             $options = array_shift($options);
             foreach ($options as $option) {
                 try {
                     $style->setOption($option);
                 } catch (\InvalidArgumentException $e) {
                     @trigger_error(sprintf('Unknown style options are deprecated since version 3.2 and will be removed in 4.0. Exception "%s".', $e->getMessage()), E_USER_DEPRECATED);
                     return false;
                 }
             }
         } else {
             return false;
         }
     }
     return $style;
 }
 /**
  * Sets an option
  *
  * @author             Art <*****@*****.**>
  *
  * @param string $opt The option
  *
  * @codeCoverageIgnore - nothing to test.
  */
 public function setOption($opt)
 {
     $this->symfony->setOption($opt);
 }