8000 Merge remote branch 'brikou/console_formatter_helper' · DerekRoth/symfony@18c3049 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18c3049

Browse files
committed
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)
2 parents 404c452 + 597a646 commit 18c3049

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

src/Symfony/Component/Console/Helper/FormatterHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function formatBlock($messages, $style, $large = false)
7474
*/
7575
private function strlen($string)
7676
{
77-
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
77+
return function_exists('mb_strlen') ? mb_strlen($string, mb_detect_encoding($string)) : strlen($string);
7878
}
7979

8080
/**

tests/Symfony/Tests/Component/Console/Helper/FormatterHelperTest.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,44 @@ public function testFormatSection()
1919
{
2020
$formatter = new FormatterHelper();
2121

22-
$this->assertEquals('<info>[cli]</info> Some text to display', $formatter->formatSection('cli', 'Some text to display'), '::formatSection() formats a message in a section');
22+
$this->assertEquals(
23+
'<info>[cli]</info> Some text to display',
24+
$formatter->formatSection('cli', 'Some text to display'),
25+
'::formatSection() formats a message in a section'
26+
);
2327
}
2428

2529
public function testFormatBlock()
2630
{
2731
$formatter = new FormatterHelper();
2832

29-
$this->assertEquals('<error> Some text to display </error>', $formatter->formatBlock('Some text to display', 'error'), '::formatBlock() formats a message in a block');
30-
$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');
31-
32-
$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');
33+
$this->assertEquals(
34+
'<error> Some text to display </error>',
35+
$formatter->formatBlock('Some text to display', 'error'),
36+
'::formatBlock() formats a message in a block'
37+
);
38+
39+
$this->assertEquals(
40+
'<error> Some text to display </error>' . "\n" .
41+
'<error> foo bar </error>',
42+
$formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
43+
'::formatBlock() formats a message in a block'
44+
);
45+
46+
$this->assertEquals(
47+
'<error> </error>' . "\n" .
48+
'<error> Some text to display </error>' . "\n" .
49+
'<error> </error>',
50+
$formatter->formatBlock('Some text to display', 'error', true),
51+
'::formatBlock() formats a message in a block'
52+
);
53+
54+
$this->assertEquals(
55+
'<error> </error>' . "\n" .
56+
'<error> Du texte à afficher </error>' . "\n" .
57+
'<error> </error>',
58+
$formatter->formatBlock('Du texte à afficher', 'error', true),
59+
'::formatBlock() formats a message in a block'
60+
);
3361
}
3462
}

0 commit comments

Comments
 (0)
0