/** * Formats a message as a block of text. * * @param string|array $messages The message to write in the block * @param string $style The style to apply to the whole block * @param bool $large Whether to return a large block * * @return string The formatter message */ public function formatBlock($messages, $style, $large = false) { $messages = (array) $messages; $len = 0; $lines = array(); foreach ($messages as $message) { $message = OutputFormatter::escape($message); $lines[] = sprintf($large ? ' %s ' : ' %s ', $message); $len = max($this->strlen($message) + ($large ? 4 : 2), $len); } $messages = $large ? array(str_repeat(' ', $len)) : array(); foreach ($lines as $line) { $messages[] = $line . str_repeat(' ', $len - $this->strlen($line)); } if ($large) { $messages[] = str_repeat(' ', $len); } foreach ($messages as &$message) { $message = sprintf('<%s>%s</%s>', $style, $message, $style); } return implode("\n", $messages); }
public function testContentWithLineBreaks() { $formatter = new OutputFormatter(true); $this->assertEquals(<<<EOF [32m some text[39m EOF , $formatter->format(<<<EOF <info> some text</info> EOF )); $this->assertEquals(<<<EOF [32msome text [39m EOF , $formatter->format(<<<EOF <info>some text </info> EOF )); $this->assertEquals(<<<EOF [32m some text [39m EOF , $formatter->format(<<<EOF <info> some text </info> EOF )); $this->assertEquals(<<<EOF [32m some text more text [39m EOF , $formatter->format(<<<EOF <info> some text more text </info> EOF )); }