Skip to content
Permalink
Browse files

Use traditional array syntax

  • Loading branch information...
Gareth Ellis
Gareth Ellis committed Dec 1, 2015
1 parent 1bd22e5 commit 3f992695b28eea7597220425466bfa3463088123
@@ -81,7 +81,7 @@ public function output($args) {
* @param array $args The initialization data.
* @return void
*/
public function init(array $args = []) {
public function init(array $args = array()) {
$args += ['total' => 100, 'width' => 80];
$this->_progress = 0;
$this->_width = $args['width'];
@@ -25,11 +25,11 @@ class TableShellHelper extends ShellHelper {
*
* @var array
*/
protected $_defaultConfig = [
protected $_defaultConfig = array(
'headers' => true,
'rowSeparator' => false,
'headerStyle' => 'info',
];
);
/**
* Calculate the column widths
@@ -38,7 +38,7 @@ class TableShellHelper extends ShellHelper {
* @return array
*/
protected function _calculateWidths($rows) {
$widths = [];
$widths = array();
foreach ($rows as $line) {
for ($i = 0, $len = count($line); $i < $len; $i++) {
$columnLength = mb_strlen($line[$i]);
@@ -73,7 +73,7 @@ protected function _rowSeparator($widths) {
* @param array $options Options to be passed.
* @return void
*/
protected function _render($row, $widths, $options = []) {
protected function _render($row, $widths, $options = array()) {
$out = '';
foreach ($row as $i => $column) {
$pad = $widths[$i] - mb_strlen($column);
@@ -41,7 +41,7 @@ public function setUp() {
* @return void
*/
public function testOutputFailure() {
$this->helper->output(['not a callback']);
$this->helper->output(array('not a callback'));
}
/**
@@ -50,10 +50,10 @@ public function testOutputFailure() {
* @return void
*/
public function testOutputSuccess() {
$this->helper->output([function ($progress) {
$this->helper->output(array(function ($progress) {
$progress->increment(20);
}]);
$expected = [
}));
$expected = array(
'',
'==============> 20%',
'',
@@ -65,7 +65,7 @@ public function testOutputSuccess() {
'',
'==========================================================================> 100%',
'',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -75,14 +75,14 @@ public function testOutputSuccess() {
* @return void
*/
public function testOutputSuccessOptions() {
$this->helper->output([
$this->helper->output(array(
'total' => 10,
'width' => 20,
'callback' => function ($progress) {
$progress->increment(2);
}
]);
$expected = [
));
$expected = array(
'',
'==> 20%',
'',
@@ -94,7 +94,7 @@ public function testOutputSuccessOptions() {
'',
'==============> 100%',
'',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -111,14 +111,14 @@ public function testIncrementAndRender() {
$this->helper->draw();
$this->helper->increment(40);
$this->helper->draw();
$expected = [
$expected = array(
'',
'==============> 20%',
'',
'============================================> 60%',
'',
'==========================================================================> 100%',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -135,14 +135,14 @@ public function testIncrementWithNegatives() {
$this->helper->draw();
$this->helper->increment(80);
$this->helper->draw();
$expected = [
$expected = array(
'',
'=============================> 40%',
'',
' 0%',
'',
'===========================================================> 80%',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -152,25 +152,25 @@ public function testIncrementWithNegatives() {
* @return void
*/
public function testIncrementWithOptions() {
$this->helper->init([
$this->helper->init(array(
'total' => 10,
'width' => 20,
]);
));
$this->helper->increment(4);
$this->helper->draw();
$this->helper->increment(4);
$this->helper->draw();
$this->helper->increment(4);
$this->helper->draw();
$expected = [
$expected = array(
'',
'=====> 40%',
'',
'===========> 80%',
'',
'==============> 100%',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -181,9 +181,9 @@ public function testIncrementWithOptions() {
* @return void
*/
public function testIncrementFloatPad() {
$this->helper->init([
$this->helper->init(array(
'total' => 50
]);
));
$this->helper->increment(7);
$this->helper->draw();
$this->helper->increment(7);
@@ -200,7 +200,7 @@ public function testIncrementFloatPad() {
$this->helper->draw();
$this->helper->increment(8);
$this->helper->draw();
$expected = [
$expected = array(
'',
'=========> 14%',
'',
@@ -217,7 +217,7 @@ public function testIncrementFloatPad() {
'==============================================================> 84%',
'',
'==========================================================================> 100%',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
}
@@ -40,20 +40,20 @@ public function setUp() {
* @return void
*/
public function testDefaultOutput() {
$data = [
['Header 1', 'Header', 'Long Header'],
['short', 'Longish thing', 'short'],
['Longer thing', 'short', 'Longest Value'],
];
$data = array(
array('Header 1', 'Header', 'Long Header'),
array('short', 'Longish thing', 'short'),
array('Longer thing', 'short', 'Longest Value'),
);
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+---------------+---------------+',
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
'+--------------+---------------+---------------+',
'| short | Longish thing | short |',
'| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -63,20 +63,20 @@ public function testDefaultOutput() {
* @return void
*/
public function testOutputUtf8() {
$data = [
['Header 1', 'Head', 'Long Header'],
['short', 'ÄÄÄÜÜÜ', 'short'],
['Longer thing', 'longerish', 'Longest Value'],
];
$data = array(
array('Header 1', 'Head', 'Long Header'),
array('short', 'ÄÄÄÜÜÜ', 'short'),
array('Longer thing', 'longerish', 'Longest Value'),
);
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+-----------+---------------+',
'| <info>Header 1</info> | <info>Head</info> | <info>Long Header</info> |',
'+--------------+-----------+---------------+',
'| short | ÄÄÄÜÜÜ | short |',
'| Longer thing | longerish | Longest Value |',
'+--------------+-----------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -86,21 +86,21 @@ public function testOutputUtf8() {
* @return void
*/
public function testOutputWithoutHeaderStyle() {
$data = [
['Header 1', 'Header', 'Long Header'],
['short', 'Longish thing', 'short'],
['Longer thing', 'short', 'Longest Value'],
];
$this->helper->config(['headerStyle' => false]);
$data = array(
array('Header 1', 'Header', 'Long Header'),
array('short', 'Longish thing', 'short'),
array('Longer thing', 'short', 'Longest Value'),
);
$this->helper->config(array('headerStyle' => false));
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+---------------+---------------+',
'| Header 1 | Header | Long Header |',
'+--------------+---------------+---------------+',
'| short | Longish thing | short |',
'| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -110,21 +110,21 @@ public function testOutputWithoutHeaderStyle() {
* @return void
*/
public function testOutputWithDifferentHeaderStyle() {
$data = [
['Header 1', 'Header', 'Long Header'],
['short', 'Longish thing', 'short'],
['Longer thing', 'short', 'Longest Value'],
];
$this->helper->config(['headerStyle' => 'error']);
$data = array(
array('Header 1', 'Header', 'Long Header'),
array('short', 'Longish thing', 'short'),
array('Longer thing', 'short', 'Longest Value'),
);
$this->helper->config(array('headerStyle' => 'error'));
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+---------------+---------------+',
'| <error>Header 1</error> | <error>Header</error> | <error>Long Header</error> |',
'+--------------+---------------+---------------+',
'| short | Longish thing | short |',
'| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -134,18 +134,18 @@ public function testOutputWithDifferentHeaderStyle() {
* @return void
*/
public function testOutputWithoutHeaders() {
$data = [
['short', 'Longish thing', 'short'],
['Longer thing', 'short', 'Longest Value'],
];
$this->helper->config(['headers' => false]);
$data = array(
array('short', 'Longish thing', 'short'),
array('Longer thing', 'short', 'Longest Value'),
);
$this->helper->config(array('headers' => false));
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+---------------+---------------+',
'| short | Longish thing | short |',
'| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -155,22 +155,22 @@ public function testOutputWithoutHeaders() {
* @return void
*/
public function testOutputWithRowSeparator() {
$data = [
['Header 1', 'Header', 'Long Header'],
['short', 'Longish thing', 'short'],
['Longer thing', 'short', 'Longest Value']
];
$this->helper->config(['rowSeparator' => true]);
$data = array(
array('Header 1', 'Header', 'Long Header'),
array('short', 'Longish thing', 'short'),
array('Longer thing', 'short', 'Longest Value')
);
$this->helper->config(array('rowSeparator' => true));
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+---------------+---------------+',
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
'+--------------+---------------+---------------+',
'| short | Longish thing | short |',
'+--------------+---------------+---------------+',
'| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
@@ -180,22 +180,22 @@ public function testOutputWithRowSeparator() {
* @return void
*/
public function testOutputWithRowSeparatorAndHeaders() {
$data = [
['Header 1', 'Header', 'Long Header'],
['short', 'Longish thing', 'short'],
['Longer thing', 'short', 'Longest Value'],
];
$this->helper->config(['rowSeparator' => true]);
$data = array(
array('Header 1', 'Header', 'Long Header'),
array('short', 'Longish thing', 'short'),
array('Longer thing', 'short', 'Longest Value'),
);
$this->helper->config(array('rowSeparator' => true));
$this->helper->output($data);
$expected = [
$expected = array(
'+--------------+---------------+---------------+',
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
'+--------------+---------------+---------------+',
'| short | Longish thing | short |',
'+--------------+---------------+---------------+',
'| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+',
];
);
$this->assertEquals($expected, $this->consoleOutput->messages());
}
}
Oops, something went wrong.

0 comments on commit 3f99269

Please sign in to comment.
You can’t perform that action at this time.