public function prepare(CommandData $commandData, FormatterOptions $options) { $width = $this->getTerminalWidth(); if (!$width) { $width = $this->defaultWidth; } // Enforce minimum and maximum widths $width = min($width, $this->getMaxWidth($commandData)); $width = max($width, $this->getMinWidth($commandData)); $options->setWidth($width); }
function testTableWithWordWrapping() { $options = new FormatterOptions(); $options->setWidth(42); $data = [['first' => 'This is a really long cell that contains a lot of data. When it is rendered, it should be wrapped across multiple lines.', 'second' => 'This is the second column of the same table. It is also very long, and should be wrapped across multiple lines, just like the first column.']]; $data = new RowsOfFields($data); $expected = <<<EOT ------------------- -------------------- First Second ------------------- -------------------- This is a really This is the second long cell that column of the same contains a lot of table. It is also data. When it is very long, and rendered, it should be wrapped should be wrapped across multiple across multiple lines, just like lines. the first column. ------------------- -------------------- EOT; $this->assertFormattedOutputMatches($expected, 'table', $data, $options); }