Merge branch '4.2'
* 4.2: fix buildTableRows when Colspan is use with content too long take setIgnoredAttributes() deprecation into account
This commit is contained in:
commit
d56ebefa98
@ -265,9 +265,13 @@ class OutputFormatter implements WrappableOutputFormatterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$lines = explode("\n", $text);
|
$lines = explode("\n", $text);
|
||||||
if ($width === $currentLineLength = \strlen(end($lines))) {
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$currentLineLength += \strlen($line);
|
||||||
|
if ($width <= $currentLineLength) {
|
||||||
$currentLineLength = 0;
|
$currentLineLength = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->isDecorated()) {
|
if ($this->isDecorated()) {
|
||||||
foreach ($lines as $i => $line) {
|
foreach ($lines as $i => $line) {
|
||||||
|
@ -523,8 +523,10 @@ class Table
|
|||||||
|
|
||||||
// Remove any new line breaks and replace it with a new line
|
// Remove any new line breaks and replace it with a new line
|
||||||
foreach ($rows[$rowKey] as $column => $cell) {
|
foreach ($rows[$rowKey] as $column => $cell) {
|
||||||
|
$colspan = $cell instanceof TableCell ? $cell->getColspan() : 1;
|
||||||
|
|
||||||
if (isset($this->columnMaxWidths[$column]) && Helper::strlenWithoutDecoration($formatter, $cell) > $this->columnMaxWidths[$column]) {
|
if (isset($this->columnMaxWidths[$column]) && Helper::strlenWithoutDecoration($formatter, $cell) > $this->columnMaxWidths[$column]) {
|
||||||
$cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column]);
|
$cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column] * $colspan);
|
||||||
}
|
}
|
||||||
if (!strstr($cell, "\n")) {
|
if (!strstr($cell, "\n")) {
|
||||||
continue;
|
continue;
|
||||||
@ -533,8 +535,8 @@ class Table
|
|||||||
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
|
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
|
||||||
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
|
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
|
||||||
foreach ($lines as $lineKey => $line) {
|
foreach ($lines as $lineKey => $line) {
|
||||||
if ($cell instanceof TableCell) {
|
if ($colspan > 1) {
|
||||||
$line = new TableCell($line, ['colspan' => $cell->getColspan()]);
|
$line = new TableCell($line, ['colspan' => $colspan]);
|
||||||
}
|
}
|
||||||
if (0 === $lineKey) {
|
if (0 === $lineKey) {
|
||||||
$rows[$rowKey][$column] = $line;
|
$rows[$rowKey][$column] = $line;
|
||||||
|
@ -327,6 +327,9 @@ EOF
|
|||||||
$this->assertSame("pre\e[37;41m\e[39;49m\n\e[37;41mfoo\e[39;49m\n\e[37;41mbar\e[39;49m\n\e[37;41mbaz\e[39;49m\npos\nt", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 3));
|
$this->assertSame("pre\e[37;41m\e[39;49m\n\e[37;41mfoo\e[39;49m\n\e[37;41mbar\e[39;49m\n\e[37;41mbaz\e[39;49m\npos\nt", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 3));
|
||||||
$this->assertSame("pre \e[37;41m\e[39;49m\n\e[37;41mfoo \e[39;49m\n\e[37;41mbar \e[39;49m\n\e[37;41mbaz\e[39;49m \npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 4));
|
$this->assertSame("pre \e[37;41m\e[39;49m\n\e[37;41mfoo \e[39;49m\n\e[37;41mbar \e[39;49m\n\e[37;41mbaz\e[39;49m \npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 4));
|
||||||
$this->assertSame("pre \e[37;41mf\e[39;49m\n\e[37;41moo ba\e[39;49m\n\e[37;41mr baz\e[39;49m\npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 5));
|
$this->assertSame("pre \e[37;41mf\e[39;49m\n\e[37;41moo ba\e[39;49m\n\e[37;41mr baz\e[39;49m\npost", $formatter->formatAndWrap('pre <error>foo bar baz</error> post', 5));
|
||||||
|
$this->assertSame("Lore\nm \e[37;41mip\e[39;49m\n\e[37;41msum\e[39;49m \ndolo\nr \e[32msi\e[39m\n\e[32mt\e[39m am\net", $formatter->formatAndWrap('Lorem <error>ipsum</error> dolor <info>sit</info> amet', 4));
|
||||||
|
$this->assertSame("Lorem \e[37;41mip\e[39;49m\n\e[37;41msum\e[39;49m dolo\nr \e[32msit\e[39m am\net", $formatter->formatAndWrap('Lorem <error>ipsum</error> dolor <info>sit</info> amet', 8));
|
||||||
|
$this->assertSame("Lorem \e[37;41mipsum\e[39;49m dolor \e[32m\e[39m\n\e[32msit\e[39m, \e[37;41mamet\e[39;49m et \e[32mlauda\e[39m\n\e[32mntium\e[39m architecto", $formatter->formatAndWrap('Lorem <error>ipsum</error> dolor <info>sit</info>, <error>amet</error> et <info>laudantium</info> architecto', 18));
|
||||||
|
|
||||||
$formatter = new OutputFormatter();
|
$formatter = new OutputFormatter();
|
||||||
|
|
||||||
|
@ -1144,4 +1144,56 @@ TABLE;
|
|||||||
|
|
||||||
return str_replace(PHP_EOL, "\n", stream_get_contents($output->getStream()));
|
return str_replace(PHP_EOL, "\n", stream_get_contents($output->getStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWithColspanAndMaxWith(): void
|
||||||
|
{
|
||||||
|
$table = new Table($output = $this->getOutputStream());
|
||||||
|
|
||||||
|
$table->setColumnMaxWidth(0, 15);
|
||||||
|
$table->setColumnMaxWidth(1, 15);
|
||||||
|
$table->setColumnMaxWidth(2, 15);
|
||||||
|
$table->setRows([
|
||||||
|
[new TableCell('Lorem ipsum dolor sit amet, <fg=white;bg=green>consectetur</> adipiscing elit, <fg=white;bg=red>sed</> do <fg=white;bg=red>eiusmod</> tempor', ['colspan' => 3])],
|
||||||
|
new TableSeparator(),
|
||||||
|
[new TableCell('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor', ['colspan' => 3])],
|
||||||
|
new TableSeparator(),
|
||||||
|
[new TableCell('Lorem ipsum <fg=white;bg=red>dolor</> sit amet, consectetur ', ['colspan' => 2]), 'hello world'],
|
||||||
|
new TableSeparator(),
|
||||||
|
['hello <fg=white;bg=green>world</>', new TableCell('Lorem ipsum dolor sit amet, <fg=white;bg=green>consectetur</> adipiscing elit', ['colspan' => 2])],
|
||||||
|
new TableSeparator(),
|
||||||
|
['hello ', new TableCell('world', ['colspan' => 1]), 'Lorem ipsum dolor sit amet, consectetur'],
|
||||||
|
new TableSeparator(),
|
||||||
|
['Symfony ', new TableCell('Test', ['colspan' => 1]), 'Lorem <fg=white;bg=green>ipsum</> dolor sit amet, consectetur'],
|
||||||
|
])
|
||||||
|
;
|
||||||
|
$table->render();
|
||||||
|
|
||||||
|
$expected =
|
||||||
|
<<<TABLE
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
| Lorem ipsum dolor sit amet, consectetur adipi |
|
||||||
|
| scing elit, sed do eiusmod tempor |
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
| Lorem ipsum dolor sit amet, consectetur adipi |
|
||||||
|
| scing elit, sed do eiusmod tempor |
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
| Lorem ipsum dolor sit amet, co | hello world |
|
||||||
|
| nsectetur | |
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
| hello world | Lorem ipsum dolor sit amet, co |
|
||||||
|
| | nsectetur adipiscing elit |
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
| hello | world | Lorem ipsum dol |
|
||||||
|
| | | or sit amet, co |
|
||||||
|
| | | nsectetur |
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
| Symfony | Test | Lorem ipsum dol |
|
||||||
|
| | | or sit amet, co |
|
||||||
|
| | | nsectetur |
|
||||||
|
+-----------------+-----------------+-----------------+
|
||||||
|
|
||||||
|
TABLE;
|
||||||
|
|
||||||
|
$this->assertSame($expected, $this->getOutputContent($output));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,8 @@ class ObjectNormalizerTest extends TestCase
|
|||||||
$this->normalizer->normalize($obj, 'any')
|
$this->normalizer->normalize($obj, 'any')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->normalizer->setIgnoredAttributes(['foo', 'baz', 'camelCase', 'object']);
|
$ignoredAttributes = ['foo', 'baz', 'camelCase', 'object'];
|
||||||
|
$legacy ? $this->normalizer->setIgnoredAttributes($ignoredAttributes) : $this->createNormalizer([ObjectNormalizer::IGNORED_ATTRIBUTES => $ignoredAttributes]);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
[
|
[
|
||||||
|
Reference in New Issue
Block a user