From 73fddb004ea6ff31741e60f1d1da8261c8fcdf1b Mon Sep 17 00:00:00 2001 From: Dmitry Dorogin Date: Sun, 24 Dec 2017 15:23:15 +0300 Subject: [PATCH] Fixes #15407 --- framework/CHANGELOG.md | 1 + framework/console/widgets/Table.php | 4 +-- tests/framework/console/widgets/TableTest.php | 37 ++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 79b7471..a0523fd 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -24,6 +24,7 @@ Yii Framework 2 Change Log - Bug #15355: Fixed `yii\db\Query::from()` does not work with `yii\db\Expression` (vladis84, silverfire, samdark) - Bug #15356: Fixed multiple bugs in `yii\db\Query::getTablesUsedInFrom()` (vladis84, samdark) - Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly) +- Bug #15407: Fixed rendering rows with associative arrays in `yii\console\widgets\Table` (dmrogin) - Enh #3087: Added `yii\helpers\BaseHtml::error()` "errorSource" option to be able to customize errors display (yanggs07, developeruz, silverfire) - Enh #3250: Added support for events partial wildcard matching (klimov-paul) - Enh #5515: Added default value for `yii\behaviors\BlameableBehavior` for cases when the user is guest (dmirogin) diff --git a/framework/console/widgets/Table.php b/framework/console/widgets/Table.php index 1e17358..400a731 100644 --- a/framework/console/widgets/Table.php +++ b/framework/console/widgets/Table.php @@ -117,7 +117,7 @@ class Table extends Widget */ public function setHeaders(array $headers) { - $this->_headers = $headers; + $this->_headers = array_values($headers); return $this; } @@ -129,7 +129,7 @@ class Table extends Widget */ public function setRows(array $rows) { - $this->_rows = $rows; + $this->_rows = array_map('array_values', $rows); return $this; } diff --git a/tests/framework/console/widgets/TableTest.php b/tests/framework/console/widgets/TableTest.php index 7435a2a..2d62726 100644 --- a/tests/framework/console/widgets/TableTest.php +++ b/tests/framework/console/widgets/TableTest.php @@ -21,7 +21,30 @@ class TableTest extends TestCase $this->mockApplication(); } - public function testTable() + public function getTableData() + { + return [ + [ + ['test1', 'test2', 'test3'], + [ + ['testcontent1', 'testcontent2', 'testcontent3'], + ['testcontent21', 'testcontent22', 'testcontent23'], + ] + ], + [ + ['key1' => 'test1', 'key2' => 'test2', 'key3' => 'test3'], + [ + ['key1' => 'testcontent1', 'key2' => 'testcontent2', 'key3' => 'testcontent3'], + ['key1' => 'testcontent21', 'key2' => 'testcontent22', 'key3' => 'testcontent23'], + ] + ] + ]; + } + + /** + * @dataProvider getTableData + */ + public function testTable($headers, $rows) { $table = new Table(); @@ -36,12 +59,12 @@ class TableTest extends TestCase EXPECTED; - $this->assertEqualsWithoutLE($expected, $table->setHeaders(['test1', 'test2', 'test3']) - ->setRows([ - ['testcontent1', 'testcontent2', 'testcontent3'], - ['testcontent21', 'testcontent22', 'testcontent23'], - ])->setScreenWidth(200)->run() - ); + $tableContent = $table + ->setHeaders($headers) + ->setRows($rows) + ->setScreenWidth(200) + ->run(); + $this->assertEqualsWithoutLE($expected, $tableContent); } public function testTableWithFullwidthChars()