Bladeren bron

Merge remote branch 'brikou/console_formatter_helper'

* brikou/console_formatter_helper:
  added mb_detect_encoding when formatting block (usefull when mb_internal_encoding is not properly set)
Fabien Potencier 14 jaren geleden
bovenliggende
commit
18c3049fad

+ 1 - 1
src/Symfony/Component/Console/Helper/FormatterHelper.php

@@ -74,7 +74,7 @@ class FormatterHelper extends Helper
      */
     private function strlen($string)
     {
-        return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
+        return function_exists('mb_strlen') ? mb_strlen($string, mb_detect_encoding($string)) : strlen($string);
     }
 
     /**

+ 33 - 5
tests/Symfony/Tests/Component/Console/Helper/FormatterHelperTest.php

@@ -19,16 +19,44 @@ class FormatterHelperTest extends \PHPUnit_Framework_TestCase
     {
         $formatter = new FormatterHelper();
 
-        $this->assertEquals('<info>[cli]</info> Some text to display', $formatter->formatSection('cli', 'Some text to display'), '::formatSection() formats a message in a section');
+        $this->assertEquals(
+            '<info>[cli]</info> Some text to display',
+            $formatter->formatSection('cli', 'Some text to display'),
+            '::formatSection() formats a message in a section'
+        );
     }
 
     public function testFormatBlock()
     {
         $formatter = new FormatterHelper();
 
-        $this->assertEquals('<error> Some text to display </error>', $formatter->formatBlock('Some text to display', 'error'), '::formatBlock() formats a message in a block');
-        $this->assertEquals("<error> Some text to display </error>\n<error> foo bar              </error>", $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'), '::formatBlock() formats a message in a block');
-
-        $this->assertEquals("<error>                        </error>\n<error>  Some text to display  </error>\n<error>                        </error>", $formatter->formatBlock('Some text to display', 'error', true), '::formatBlock() formats a message in a block');
+        $this->assertEquals(
+            '<error> Some text to display </error>',
+            $formatter->formatBlock('Some text to display', 'error'),
+            '::formatBlock() formats a message in a block'
+        );
+
+        $this->assertEquals(
+            '<error> Some text to display </error>' . "\n" .
+            '<error> foo bar              </error>',
+            $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
+            '::formatBlock() formats a message in a block'
+        );
+
+        $this->assertEquals(
+            '<error>                        </error>' . "\n" .
+            '<error>  Some text to display  </error>' . "\n" .
+            '<error>                        </error>',
+            $formatter->formatBlock('Some text to display', 'error', true),
+            '::formatBlock() formats a message in a block'
+        );
+
+        $this->assertEquals(
+            '<error>                       </error>' . "\n" .
+            '<error>  Du texte à afficher  </error>' . "\n" .
+            '<error>                       </error>',
+            $formatter->formatBlock('Du texte à afficher', 'error', true),
+            '::formatBlock() formats a message in a block'
+        );
     }
 }