render() public method

Overrides Table->render(), to adapt all the cells to the table width.
public render ( )
 /**
  * Test that a wide table is adapted to a maximum width.
  */
 public function testAdaptedRowsFitMaxTableWidth()
 {
     $maxTableWidth = 60;
     $buffer = new BufferedOutput();
     $table = new AdaptiveTable($buffer, $maxTableWidth);
     $table->setHeaders([['Row', 'Lorem', 'ipsum', 'dolor', 'sit']]);
     $table->setRows([['#1', 'amet', 'consectetur', 'adipiscing elit', 'Quisque pulvinar'], ['#2', 'tellus sit amet', 'sollicitudin', 'tincidunt', 'risus'], ['#3', 'risus', 'sem', 'mattis', 'ex'], ['#4', 'quis', 'luctus metus', 'lorem cursus', 'ligula']]);
     $table->render();
     // Test that the table fits into the maximum width.
     $lineWidths = [];
     foreach (explode(PHP_EOL, $buffer->fetch()) as $line) {
         $lineWidths[] = strlen($line);
     }
     $this->assertLessThanOrEqual($maxTableWidth, max($lineWidths));
 }
Esempio n. 2
0
 /**
  * Render a Symfony Console table.
  *
  * @param array $rows
  * @param array $header
  */
 protected function renderTable(array $rows, array $header)
 {
     $table = new AdaptiveTable($this->output);
     $table->setHeaders($header);
     $table->setRows($rows);
     $table->render();
 }