Преглед изворни кода

if proper style not found, then this is a tag - no need in Exception

ever.zet пре 14 година
родитељ
комит
5ec8f47d7c

+ 5 - 1
src/Symfony/Component/Console/Output/Output.php

@@ -198,7 +198,7 @@ abstract class Output implements OutputInterface
         } else {
             // bg=blue;fg=red
             if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($match[1]), $matches, PREG_SET_ORDER)) {
-                throw new \InvalidArgumentException(sprintf('Unknown style "%s".', $match[1]));
+                return $match[0];
             }
 
             $parameters = array();
@@ -235,6 +235,10 @@ abstract class Output implements OutputInterface
      */
     private function replaceEndStyle($match)
     {
+        if (!isset(self::$styles[strtolower($match[1])])) {
+            return $match[0];
+        }
+
         if (!$this->decorated) {
             return '';
         }

+ 7 - 7
tests/Symfony/Tests/Component/Console/Output/OutputTest.php

@@ -84,13 +84,13 @@ class OutputTest extends \PHPUnit_Framework_TestCase
             $this->assertEquals('Unknown output type given (24)', $e->getMessage());
         }
 
-        try {
-            $output->writeln('<bar>foo</bar>');
-            $this->fail('->writeln() throws an \InvalidArgumentException when a style does not exist');
-        } catch (\Exception $e) {
-            $this->assertInstanceOf('\InvalidArgumentException', $e, '->writeln() throws an \InvalidArgumentException when a style does not exist');
-            $this->assertEquals('Unknown style "bar".', $e->getMessage());
-        }
+        $output->clear();
+        $output->write('<bar>foo</bar>');
+        $this->assertEquals('<bar>foo</bar>', $output->output, '->write() do nothing when a style does not exist');
+
+        $output->clear();
+        $output->writeln('<bar>foo</bar>');
+        $this->assertEquals("<bar>foo</bar>\n", $output->output, '->writeln() do nothing when a style does not exist');
     }
 }