mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 13:58:55 +08:00
Allow \yii\console\widgets\Table to render empty table (#16865)
When headers provided but no columns. Ref #16858
This commit is contained in:
committed by
Alexander Makarov
parent
1fe3d61a3b
commit
e11e3eb4c5
@ -82,6 +82,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #16839: Increase frequency of lock tries for `yii\mutex\FileMutex::acquireLock()` when $timeout is provided (rob006)
|
- Enh #16839: Increase frequency of lock tries for `yii\mutex\FileMutex::acquireLock()` when $timeout is provided (rob006)
|
||||||
- Enh #16839: Add support for `$timeout` in `yii\mutex\PgsqlMutex::acquire()` (rob006)
|
- Enh #16839: Add support for `$timeout` in `yii\mutex\PgsqlMutex::acquire()` (rob006)
|
||||||
- Bug #16828: `yii\console\controllers\MessageController::translator` recognized object' methods and functions calls as identical sets of tokens (erickskrauch)
|
- Bug #16828: `yii\console\controllers\MessageController::translator` recognized object' methods and functions calls as identical sets of tokens (erickskrauch)
|
||||||
|
- Bug #16858: Allow `\yii\console\widgets\Table` to render empty table when headers provided but no columns (damiandziaduch)
|
||||||
|
|
||||||
|
|
||||||
2.0.15.1 March 21, 2018
|
2.0.15.1 March 21, 2018
|
||||||
|
|||||||
@ -310,7 +310,11 @@ class Table extends Widget
|
|||||||
$screenWidth = $this->getScreenWidth() - self::CONSOLE_SCROLLBAR_OFFSET;
|
$screenWidth = $this->getScreenWidth() - self::CONSOLE_SCROLLBAR_OFFSET;
|
||||||
|
|
||||||
$headerCount = count($this->_headers);
|
$headerCount = count($this->_headers);
|
||||||
|
if (empty($this->_rows)) {
|
||||||
|
$rowColCount = 0;
|
||||||
|
} else {
|
||||||
$rowColCount = max(array_map('count', $this->_rows));
|
$rowColCount = max(array_map('count', $this->_rows));
|
||||||
|
}
|
||||||
$count = max($headerCount, $rowColCount);
|
$count = max($headerCount, $rowColCount);
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$columns[] = ArrayHelper::getColumn($this->_rows, $i);
|
$columns[] = ArrayHelper::getColumn($this->_rows, $i);
|
||||||
|
|||||||
@ -269,4 +269,20 @@ EXPECTED;
|
|||||||
])->setScreenWidth(200)->run()
|
])->setScreenWidth(200)->run()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyTable()
|
||||||
|
{
|
||||||
|
$table = new Table();
|
||||||
|
|
||||||
|
$expected = <<<'EXPECTED'
|
||||||
|
╔═══════╤═══════╤═══════╗
|
||||||
|
║ test1 │ test2 │ test3 ║
|
||||||
|
╚═══════╧═══════╧═══════╝
|
||||||
|
|
||||||
|
EXPECTED;
|
||||||
|
|
||||||
|
$this->assertEqualsWithoutLE($expected, $table->setHeaders(['test1', 'test2', 'test3'])
|
||||||
|
->setRows([])->setScreenWidth(200)->run()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user