Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmirogin authored and SilverFire committed Dec 24, 2017
1 parent c4e1ea2 commit 73fddb0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions framework/console/widgets/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Table extends Widget
*/
public function setHeaders(array $headers)
{
$this->_headers = $headers;
$this->_headers = array_values($headers);
return $this;
}

Expand All @@ -129,7 +129,7 @@ public function setHeaders(array $headers)
*/
public function setRows(array $rows)
{
$this->_rows = $rows;
$this->_rows = array_map('array_values', $rows);
return $this;
}

Expand Down
37 changes: 30 additions & 7 deletions tests/framework/console/widgets/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,30 @@ protected function setUp()
$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();

Expand All @@ -36,12 +59,12 @@ public function testTable()

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()
Expand Down

0 comments on commit 73fddb0

Please sign in to comment.