Use traditional array syntax

This commit is contained in:
Gareth Ellis 2015-12-01 15:16:54 +00:00
parent 1bd22e5277
commit 3f992695b2
6 changed files with 84 additions and 84 deletions

View file

@ -81,7 +81,7 @@ class ProgressShellHelper extends ShellHelper {
* @param array $args The initialization data. * @param array $args The initialization data.
* @return void * @return void
*/ */
public function init(array $args = []) { public function init(array $args = array()) {
$args += ['total' => 100, 'width' => 80]; $args += ['total' => 100, 'width' => 80];
$this->_progress = 0; $this->_progress = 0;
$this->_width = $args['width']; $this->_width = $args['width'];

View file

@ -25,11 +25,11 @@ class TableShellHelper extends ShellHelper {
* *
* @var array * @var array
*/ */
protected $_defaultConfig = [ protected $_defaultConfig = array(
'headers' => true, 'headers' => true,
'rowSeparator' => false, 'rowSeparator' => false,
'headerStyle' => 'info', 'headerStyle' => 'info',
]; );
/** /**
* Calculate the column widths * Calculate the column widths
@ -38,7 +38,7 @@ class TableShellHelper extends ShellHelper {
* @return array * @return array
*/ */
protected function _calculateWidths($rows) { protected function _calculateWidths($rows) {
$widths = []; $widths = array();
foreach ($rows as $line) { foreach ($rows as $line) {
for ($i = 0, $len = count($line); $i < $len; $i++) { for ($i = 0, $len = count($line); $i < $len; $i++) {
$columnLength = mb_strlen($line[$i]); $columnLength = mb_strlen($line[$i]);
@ -73,7 +73,7 @@ class TableShellHelper extends ShellHelper {
* @param array $options Options to be passed. * @param array $options Options to be passed.
* @return void * @return void
*/ */
protected function _render($row, $widths, $options = []) { protected function _render($row, $widths, $options = array()) {
$out = ''; $out = '';
foreach ($row as $i => $column) { foreach ($row as $i => $column) {
$pad = $widths[$i] - mb_strlen($column); $pad = $widths[$i] - mb_strlen($column);

View file

@ -41,7 +41,7 @@ class ProgressShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputFailure() { public function testOutputFailure() {
$this->helper->output(['not a callback']); $this->helper->output(array('not a callback'));
} }
/** /**
@ -50,10 +50,10 @@ class ProgressShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputSuccess() { public function testOutputSuccess() {
$this->helper->output([function ($progress) { $this->helper->output(array(function ($progress) {
$progress->increment(20); $progress->increment(20);
}]); }));
$expected = [ $expected = array(
'', '',
'==============> 20%', '==============> 20%',
'', '',
@ -65,7 +65,7 @@ class ProgressShellHelperTest extends CakeTestCase {
'', '',
'==========================================================================> 100%', '==========================================================================> 100%',
'', '',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -75,14 +75,14 @@ class ProgressShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputSuccessOptions() { public function testOutputSuccessOptions() {
$this->helper->output([ $this->helper->output(array(
'total' => 10, 'total' => 10,
'width' => 20, 'width' => 20,
'callback' => function ($progress) { 'callback' => function ($progress) {
$progress->increment(2); $progress->increment(2);
} }
]); ));
$expected = [ $expected = array(
'', '',
'==> 20%', '==> 20%',
'', '',
@ -94,7 +94,7 @@ class ProgressShellHelperTest extends CakeTestCase {
'', '',
'==============> 100%', '==============> 100%',
'', '',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -111,14 +111,14 @@ class ProgressShellHelperTest extends CakeTestCase {
$this->helper->draw(); $this->helper->draw();
$this->helper->increment(40); $this->helper->increment(40);
$this->helper->draw(); $this->helper->draw();
$expected = [ $expected = array(
'', '',
'==============> 20%', '==============> 20%',
'', '',
'============================================> 60%', '============================================> 60%',
'', '',
'==========================================================================> 100%', '==========================================================================> 100%',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -135,14 +135,14 @@ class ProgressShellHelperTest extends CakeTestCase {
$this->helper->draw(); $this->helper->draw();
$this->helper->increment(80); $this->helper->increment(80);
$this->helper->draw(); $this->helper->draw();
$expected = [ $expected = array(
'', '',
'=============================> 40%', '=============================> 40%',
'', '',
' 0%', ' 0%',
'', '',
'===========================================================> 80%', '===========================================================> 80%',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -152,10 +152,10 @@ class ProgressShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testIncrementWithOptions() { public function testIncrementWithOptions() {
$this->helper->init([ $this->helper->init(array(
'total' => 10, 'total' => 10,
'width' => 20, 'width' => 20,
]); ));
$this->helper->increment(4); $this->helper->increment(4);
$this->helper->draw(); $this->helper->draw();
$this->helper->increment(4); $this->helper->increment(4);
@ -163,14 +163,14 @@ class ProgressShellHelperTest extends CakeTestCase {
$this->helper->increment(4); $this->helper->increment(4);
$this->helper->draw(); $this->helper->draw();
$expected = [ $expected = array(
'', '',
'=====> 40%', '=====> 40%',
'', '',
'===========> 80%', '===========> 80%',
'', '',
'==============> 100%', '==============> 100%',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -181,9 +181,9 @@ class ProgressShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testIncrementFloatPad() { public function testIncrementFloatPad() {
$this->helper->init([ $this->helper->init(array(
'total' => 50 'total' => 50
]); ));
$this->helper->increment(7); $this->helper->increment(7);
$this->helper->draw(); $this->helper->draw();
$this->helper->increment(7); $this->helper->increment(7);
@ -200,7 +200,7 @@ class ProgressShellHelperTest extends CakeTestCase {
$this->helper->draw(); $this->helper->draw();
$this->helper->increment(8); $this->helper->increment(8);
$this->helper->draw(); $this->helper->draw();
$expected = [ $expected = array(
'', '',
'=========> 14%', '=========> 14%',
'', '',
@ -217,7 +217,7 @@ class ProgressShellHelperTest extends CakeTestCase {
'==============================================================> 84%', '==============================================================> 84%',
'', '',
'==========================================================================> 100%', '==========================================================================> 100%',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
} }

View file

@ -40,20 +40,20 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDefaultOutput() { public function testDefaultOutput() {
$data = [ $data = array(
['Header 1', 'Header', 'Long Header'], array('Header 1', 'Header', 'Long Header'),
['short', 'Longish thing', 'short'], array('short', 'Longish thing', 'short'),
['Longer thing', 'short', 'Longest Value'], array('Longer thing', 'short', 'Longest Value'),
]; );
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |', '| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| short | Longish thing | short |', '| short | Longish thing | short |',
'| Longer thing | short | Longest Value |', '| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -63,20 +63,20 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputUtf8() { public function testOutputUtf8() {
$data = [ $data = array(
['Header 1', 'Head', 'Long Header'], array('Header 1', 'Head', 'Long Header'),
['short', 'ÄÄÄÜÜÜ', 'short'], array('short', 'ÄÄÄÜÜÜ', 'short'),
['Longer thing', 'longerish', 'Longest Value'], array('Longer thing', 'longerish', 'Longest Value'),
]; );
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+-----------+---------------+', '+--------------+-----------+---------------+',
'| <info>Header 1</info> | <info>Head</info> | <info>Long Header</info> |', '| <info>Header 1</info> | <info>Head</info> | <info>Long Header</info> |',
'+--------------+-----------+---------------+', '+--------------+-----------+---------------+',
'| short | ÄÄÄÜÜÜ | short |', '| short | ÄÄÄÜÜÜ | short |',
'| Longer thing | longerish | Longest Value |', '| Longer thing | longerish | Longest Value |',
'+--------------+-----------+---------------+', '+--------------+-----------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -86,21 +86,21 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputWithoutHeaderStyle() { public function testOutputWithoutHeaderStyle() {
$data = [ $data = array(
['Header 1', 'Header', 'Long Header'], array('Header 1', 'Header', 'Long Header'),
['short', 'Longish thing', 'short'], array('short', 'Longish thing', 'short'),
['Longer thing', 'short', 'Longest Value'], array('Longer thing', 'short', 'Longest Value'),
]; );
$this->helper->config(['headerStyle' => false]); $this->helper->config(array('headerStyle' => false));
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| Header 1 | Header | Long Header |', '| Header 1 | Header | Long Header |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| short | Longish thing | short |', '| short | Longish thing | short |',
'| Longer thing | short | Longest Value |', '| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -110,21 +110,21 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputWithDifferentHeaderStyle() { public function testOutputWithDifferentHeaderStyle() {
$data = [ $data = array(
['Header 1', 'Header', 'Long Header'], array('Header 1', 'Header', 'Long Header'),
['short', 'Longish thing', 'short'], array('short', 'Longish thing', 'short'),
['Longer thing', 'short', 'Longest Value'], array('Longer thing', 'short', 'Longest Value'),
]; );
$this->helper->config(['headerStyle' => 'error']); $this->helper->config(array('headerStyle' => 'error'));
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| <error>Header 1</error> | <error>Header</error> | <error>Long Header</error> |', '| <error>Header 1</error> | <error>Header</error> | <error>Long Header</error> |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| short | Longish thing | short |', '| short | Longish thing | short |',
'| Longer thing | short | Longest Value |', '| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -134,18 +134,18 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputWithoutHeaders() { public function testOutputWithoutHeaders() {
$data = [ $data = array(
['short', 'Longish thing', 'short'], array('short', 'Longish thing', 'short'),
['Longer thing', 'short', 'Longest Value'], array('Longer thing', 'short', 'Longest Value'),
]; );
$this->helper->config(['headers' => false]); $this->helper->config(array('headers' => false));
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| short | Longish thing | short |', '| short | Longish thing | short |',
'| Longer thing | short | Longest Value |', '| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -155,14 +155,14 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputWithRowSeparator() { public function testOutputWithRowSeparator() {
$data = [ $data = array(
['Header 1', 'Header', 'Long Header'], array('Header 1', 'Header', 'Long Header'),
['short', 'Longish thing', 'short'], array('short', 'Longish thing', 'short'),
['Longer thing', 'short', 'Longest Value'] array('Longer thing', 'short', 'Longest Value')
]; );
$this->helper->config(['rowSeparator' => true]); $this->helper->config(array('rowSeparator' => true));
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |', '| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
@ -170,7 +170,7 @@ class TableShellHelperTest extends CakeTestCase {
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| Longer thing | short | Longest Value |', '| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
@ -180,14 +180,14 @@ class TableShellHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOutputWithRowSeparatorAndHeaders() { public function testOutputWithRowSeparatorAndHeaders() {
$data = [ $data = array(
['Header 1', 'Header', 'Long Header'], array('Header 1', 'Header', 'Long Header'),
['short', 'Longish thing', 'short'], array('short', 'Longish thing', 'short'),
['Longer thing', 'short', 'Longest Value'], array('Longer thing', 'short', 'Longest Value'),
]; );
$this->helper->config(['rowSeparator' => true]); $this->helper->config(array('rowSeparator' => true));
$this->helper->output($data); $this->helper->output($data);
$expected = [ $expected = array(
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |', '| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
@ -195,7 +195,7 @@ class TableShellHelperTest extends CakeTestCase {
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
'| Longer thing | short | Longest Value |', '| Longer thing | short | Longest Value |',
'+--------------+---------------+---------------+', '+--------------+---------------+---------------+',
]; );
$this->assertEquals($expected, $this->consoleOutput->messages()); $this->assertEquals($expected, $this->consoleOutput->messages());
} }
} }

View file

@ -45,8 +45,8 @@ class ConsoleOutputStubTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testWrite() { public function testWrite() {
$this->stub->write(["foo", "bar", "baz"]); $this->stub->write(array("foo", "bar", "baz"));
$this->assertEquals(["foo", "bar", "baz"], $this->stub->messages()); $this->assertEquals(array("foo", "bar", "baz"), $this->stub->messages());
} }
/** /**
@ -55,8 +55,8 @@ class ConsoleOutputStubTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testOverwrite() { public function testOverwrite() {
$this->stub->write(["foo", "bar", "baz"]); $this->stub->write(array("foo", "bar", "baz"));
$this->stub->overwrite("bat"); $this->stub->overwrite("bat");
$this->assertEquals(["foo", "bar", "baz", "", "bat"], $this->stub->messages()); $this->assertEquals(array("foo", "bar", "baz", "", "bat"), $this->stub->messages());
} }
} }

View file

@ -33,7 +33,7 @@ class ConsoleOutputStub extends ConsoleOutput {
* *
* @var array * @var array
*/ */
protected $_out = []; protected $_out = array();
/** /**
* The number of bytes written by last call to write * The number of bytes written by last call to write