From 1988aa03f28df7399010c2dfcc16dc49ef723a6c Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 18 Feb 2016 12:27:23 -0500 Subject: [PATCH 01/10] Adding missing test coverage for old input and binding on multiple select. --- tests/FormBuilderTest.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index a52828b..2de53ed 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -272,6 +272,23 @@ public function testRenderSelectWithOldInput() $this->assertEquals($expected, $result); } + public function testRenderMultipleSelectWithOldInput() + { + $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); + $oldInput->shouldReceive('hasOldInput')->andReturn(true); + $oldInput->shouldReceive('getOldInput')->with('favourite_foods')->andReturn(array(0 => 'fish', 1 => 'chips')); + + $this->form->setOldInputProvider($oldInput); + + $expected = ''; + $result = (string)$this->form->select('favourite_foods', array('fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'))->multiple(); + $this->assertEquals($expected, $result); + } + public function testRenderTextAreaWithOldInput() { $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); @@ -532,6 +549,20 @@ public function testBindSelect() $this->assertEquals($expected, $result); } + public function testBindMultipleSelect() + { + $object = $this->getStubObject(); + $this->form->bind($object); + + $expected = ''; + $result = (string)$this->form->select('favourite_foods', array('fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'))->multiple(); + $this->assertEquals($expected, $result); + } + public function testBindHidden() { $object = $this->getStubObject(); @@ -681,6 +712,7 @@ private function getStubObject() $obj->terms = 'agree'; $obj->color = 'green'; $obj->number = '0'; + $obj->favourite_foods = array('fish', 'chips'); return $obj; } } From 096c96f0c3ceb7cb7be1c75d24e9ab3b5927abfb Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 18 Feb 2016 13:31:50 -0500 Subject: [PATCH 02/10] Adding failing test coverage for old input and binding checkbox arrays. --- tests/FormBuilderTest.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 2de53ed..31f472e 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -172,6 +172,27 @@ public function testRenderCheckboxWithOldInput() $this->assertEquals($expected, $result); } + public function testRenderCheckboxArrayWithOldInput() + { + $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); + $oldInput->shouldReceive('hasOldInput')->andReturn(true); + $oldInput->shouldReceive('getOldInput')->with('favourite_foods')->andReturn(array(0 => 'fish', 1 => 'chips')); + + $this->form->setOldInputProvider($oldInput); + + $expected = ''; + $result = (string)$this->form->checkbox('favourite_foods[]', 'fish'); + $this->assertEquals($expected, $result); + + $expected = ''; + $result = (string)$this->form->checkbox('favourite_foods[]', 'tofu'); + $this->assertEquals($expected, $result); + + $expected = ''; + $result = (string)$this->form->checkbox('favourite_foods[]', 'chips'); + $this->assertEquals($expected, $result); + } + public function testRenderRadioWithOldInput() { $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); @@ -595,6 +616,24 @@ public function testBindCheckbox() $this->assertEquals($expected, $result); } + public function testBindCheckboxArray() + { + $object = $this->getStubObject(); + $this->form->bind($object); + + $expected = ''; + $result = (string)$this->form->checkbox('favourite_foods[]', 'fish'); + $this->assertEquals($expected, $result); + + $expected = ''; + $result = (string)$this->form->checkbox('favourite_foods[]', 'tofu'); + $this->assertEquals($expected, $result); + + $expected = ''; + $result = (string)$this->form->checkbox('favourite_foods[]', 'chips'); + $this->assertEquals($expected, $result); + } + public function testValueTakesPrecedenceOverBinding() { $object = $this->getStubObject(); From 514e1d9b71931909ad8a5807a9e1bb75cab29bcc Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 18 Feb 2016 13:33:35 -0500 Subject: [PATCH 03/10] Making tests pass. --- src/AdamWathan/Form/Elements/Checkbox.php | 6 ++++++ src/AdamWathan/Form/FormBuilder.php | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/AdamWathan/Form/Elements/Checkbox.php b/src/AdamWathan/Form/Elements/Checkbox.php index 6080322..7b5f0f0 100644 --- a/src/AdamWathan/Form/Elements/Checkbox.php +++ b/src/AdamWathan/Form/Elements/Checkbox.php @@ -18,6 +18,12 @@ public function __construct($name, $value = 1) public function setOldValue($oldValue) { + $value = $this->getAttribute('value'); + + if (is_array($oldValue) && in_array($value, $oldValue)) { + $oldValue = $value; + } + $this->oldValue = $oldValue; } diff --git a/src/AdamWathan/Form/FormBuilder.php b/src/AdamWathan/Form/FormBuilder.php index ac3970a..1c0927e 100644 --- a/src/AdamWathan/Form/FormBuilder.php +++ b/src/AdamWathan/Form/FormBuilder.php @@ -219,6 +219,8 @@ public function bind($model) public function getValueFor($name) { + $name = $this->transformKey($name); + if ($this->hasOldInput()) { return $this->getOldInput($name); } @@ -289,4 +291,9 @@ public function selectMonth($name) return $this->select($name, $options); } + + protected function transformKey($key) + { + return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key); + } } From 02eb0168becc140d5a37432b7f4c04ae785cf509 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 18 Feb 2016 14:29:13 -0500 Subject: [PATCH 04/10] $oldValue prop should match old input provider's value. Moving array logic to checkBinding(). --- src/AdamWathan/Form/Elements/Checkbox.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/AdamWathan/Form/Elements/Checkbox.php b/src/AdamWathan/Form/Elements/Checkbox.php index 7b5f0f0..af6c9e1 100644 --- a/src/AdamWathan/Form/Elements/Checkbox.php +++ b/src/AdamWathan/Form/Elements/Checkbox.php @@ -18,12 +18,6 @@ public function __construct($name, $value = 1) public function setOldValue($oldValue) { - $value = $this->getAttribute('value'); - - if (is_array($oldValue) && in_array($value, $oldValue)) { - $oldValue = $value; - } - $this->oldValue = $oldValue; } @@ -85,8 +79,12 @@ protected function checkBinding() $currentValue = $this->getAttribute('value'); $oldValue = $this->oldValue; + if (is_array($oldValue) && in_array($currentValue, $oldValue)) { + return $this->check(); + } + if ($currentValue === $oldValue) { - $this->check(); + return $this->check(); } } From 99ff9fbbe453f9a87106d83735005a16f160efc4 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 18 Feb 2016 14:33:34 -0500 Subject: [PATCH 05/10] Adding failing test for old input on checkbox with binary true value. --- tests/FormBuilderTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 31f472e..dab8964 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -269,6 +269,19 @@ public function testRenderCheckboxAgainstBinaryZero() $this->assertEquals($expected, $result); } + public function testRenderCheckboxAgainstBinaryOldInput() + { + $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); + $oldInput->shouldReceive('hasOldInput')->andReturn(true); + $oldInput->shouldReceive('getOldInput')->with('agree_to_terms')->andReturn('1'); + + $this->form->setOldInputProvider($oldInput); + + $expected = ''; + $result = (string)$this->form->checkbox('agree_to_terms', 1); + $this->assertEquals($expected, $result); + } + public function testRenderRadioAgainstBinaryZero() { $expected = ''; From 1167327a4564c055b0a32e38946644f550a7bca9 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Thu, 18 Feb 2016 14:42:33 -0500 Subject: [PATCH 06/10] Fix for binary values not binding properly. --- src/AdamWathan/Form/Elements/Checkbox.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/AdamWathan/Form/Elements/Checkbox.php b/src/AdamWathan/Form/Elements/Checkbox.php index af6c9e1..58d3166 100644 --- a/src/AdamWathan/Form/Elements/Checkbox.php +++ b/src/AdamWathan/Form/Elements/Checkbox.php @@ -76,14 +76,13 @@ protected function setChecked($checked = true) protected function checkBinding() { - $currentValue = $this->getAttribute('value'); - $oldValue = $this->oldValue; + $currentValue = (string) $this->getAttribute('value'); - if (is_array($oldValue) && in_array($currentValue, $oldValue)) { - return $this->check(); - } + $oldValue = $this->oldValue; + $oldValue = is_array($oldValue) ? $oldValue : array($oldValue); + $oldValue = array_map('strval', $oldValue); - if ($currentValue === $oldValue) { + if (in_array($currentValue, $oldValue)) { return $this->check(); } } From 6b964a7ac3ac534e3d8825b8f42effe5a9638664 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 19 Feb 2016 14:42:55 -0500 Subject: [PATCH 07/10] Please give me arrays. (A raise. Salary pls.) --- tests/FormBuilderTest.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index dab8964..688ff4e 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -103,20 +103,20 @@ public function testButton($value, $name, $expected) public function buttonProvider() { - return array( - array('Click Me', 'click-me', ''), - array('Click Me', null, '') - ); + return [ + ['Click Me', 'click-me', ''], + ['Click Me', null, ''], + ]; } public function testSelect() { $expected = ''; - $result = (string)$this->form->select('color', array('red' => 'Red', 'blue' => 'Blue')); + $result = (string)$this->form->select('color', ['red' => 'Red', 'blue' => 'Blue']); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $result = (string)$this->form->select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $this->assertEquals($expected, $result); } @@ -176,7 +176,7 @@ public function testRenderCheckboxArrayWithOldInput() { $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); $oldInput->shouldReceive('hasOldInput')->andReturn(true); - $oldInput->shouldReceive('getOldInput')->with('favourite_foods')->andReturn(array(0 => 'fish', 1 => 'chips')); + $oldInput->shouldReceive('getOldInput')->with('favourite_foods')->andReturn(['fish', 'chips']); $this->form->setOldInputProvider($oldInput); @@ -298,11 +298,11 @@ public function testRenderSelectWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->select('color', array('red' => 'Red', 'blue' => 'Blue')); + $result = (string)$this->form->select('color', ['red' => 'Red', 'blue' => 'Blue']); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->select('color')->options(array('red' => 'Red', 'blue' => 'Blue')); + $result = (string)$this->form->select('color')->options(['red' => 'Red', 'blue' => 'Blue']); $this->assertEquals($expected, $result); } @@ -310,7 +310,7 @@ public function testRenderMultipleSelectWithOldInput() { $oldInput = Mockery::mock('AdamWathan\Form\OldInput\OldInputInterface'); $oldInput->shouldReceive('hasOldInput')->andReturn(true); - $oldInput->shouldReceive('getOldInput')->with('favourite_foods')->andReturn(array(0 => 'fish', 1 => 'chips')); + $oldInput->shouldReceive('getOldInput')->with('favourite_foods')->andReturn(['fish', 'chips']); $this->form->setOldInputProvider($oldInput); @@ -319,7 +319,7 @@ public function testRenderMultipleSelectWithOldInput() $expected .= ''; $expected .= ''; $expected .= ''; - $result = (string)$this->form->select('favourite_foods', array('fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'))->multiple(); + $result = (string)$this->form->select('favourite_foods', ['fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'])->multiple(); $this->assertEquals($expected, $result); } @@ -579,7 +579,7 @@ public function testBindSelect() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->select('gender', array('male' => 'Male', 'female' => 'Female')); + $result = (string)$this->form->select('gender', ['male' => 'Male', 'female' => 'Female']); $this->assertEquals($expected, $result); } @@ -593,7 +593,7 @@ public function testBindMultipleSelect() $expected .= ''; $expected .= ''; $expected .= ''; - $result = (string)$this->form->select('favourite_foods', array('fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'))->multiple(); + $result = (string)$this->form->select('favourite_foods', ['fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'])->multiple(); $this->assertEquals($expected, $result); } @@ -712,7 +712,7 @@ public function testBindMagicProperty() public function testBindArray() { - $model = array('first_name' => 'John'); + $model = ['first_name' => 'John']; $this->form->bind($model); $expected = ''; $result = (string)$this->form->text('first_name'); @@ -764,7 +764,7 @@ private function getStubObject() $obj->terms = 'agree'; $obj->color = 'green'; $obj->number = '0'; - $obj->favourite_foods = array('fish', 'chips'); + $obj->favourite_foods = ['fish', 'chips']; return $obj; } } From 177bad35351898b21c28f6d1637cdc69e93f36ce Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 19 Feb 2016 14:54:21 -0500 Subject: [PATCH 08/10] Getting Adam Wathan into the modern age a bit. --- src/AdamWathan/Form/Elements/Button.php | 5 +- src/AdamWathan/Form/Elements/Checkbox.php | 6 +- src/AdamWathan/Form/Elements/Date.php | 4 +- src/AdamWathan/Form/Elements/Element.php | 8 +- src/AdamWathan/Form/Elements/Email.php | 4 +- src/AdamWathan/Form/Elements/File.php | 4 +- src/AdamWathan/Form/Elements/FormOpen.php | 4 +- src/AdamWathan/Form/Elements/Hidden.php | 4 +- src/AdamWathan/Form/Elements/Password.php | 4 +- src/AdamWathan/Form/Elements/RadioButton.php | 4 +- src/AdamWathan/Form/Elements/Select.php | 3 +- src/AdamWathan/Form/Elements/Text.php | 5 +- src/AdamWathan/Form/Elements/TextArea.php | 5 +- .../Form/ErrorStore/IlluminateErrorStore.php | 2 +- src/AdamWathan/Form/FormBuilder.php | 8 +- src/AdamWathan/Form/FormServiceProvider.php | 2 +- tests/FormBuilderTest.php | 158 +++++++++--------- tests/FormOpenTest.php | 2 +- tests/InputContractTest.php | 2 +- 19 files changed, 115 insertions(+), 119 deletions(-) diff --git a/src/AdamWathan/Form/Elements/Button.php b/src/AdamWathan/Form/Elements/Button.php index 5ff89ed..2134255 100644 --- a/src/AdamWathan/Form/Elements/Button.php +++ b/src/AdamWathan/Form/Elements/Button.php @@ -2,10 +2,9 @@ class Button extends FormControl { - - protected $attributes = array( + protected $attributes = [ 'type' => 'button', - ); + ]; protected $value; diff --git a/src/AdamWathan/Form/Elements/Checkbox.php b/src/AdamWathan/Form/Elements/Checkbox.php index 58d3166..e12993a 100644 --- a/src/AdamWathan/Form/Elements/Checkbox.php +++ b/src/AdamWathan/Form/Elements/Checkbox.php @@ -2,9 +2,9 @@ class Checkbox extends Input { - protected $attributes = array( + protected $attributes = [ 'type' => 'checkbox', - ); + ]; private $checked; @@ -79,7 +79,7 @@ protected function checkBinding() $currentValue = (string) $this->getAttribute('value'); $oldValue = $this->oldValue; - $oldValue = is_array($oldValue) ? $oldValue : array($oldValue); + $oldValue = is_array($oldValue) ? $oldValue : [$oldValue]; $oldValue = array_map('strval', $oldValue); if (in_array($currentValue, $oldValue)) { diff --git a/src/AdamWathan/Form/Elements/Date.php b/src/AdamWathan/Form/Elements/Date.php index c57c2b4..83d05a9 100644 --- a/src/AdamWathan/Form/Elements/Date.php +++ b/src/AdamWathan/Form/Elements/Date.php @@ -2,9 +2,9 @@ class Date extends Text { - protected $attributes = array( + protected $attributes = [ 'type' => 'date', - ); + ]; public function value($value) { diff --git a/src/AdamWathan/Form/Elements/Element.php b/src/AdamWathan/Form/Elements/Element.php index 4663474..7ab509e 100644 --- a/src/AdamWathan/Form/Elements/Element.php +++ b/src/AdamWathan/Form/Elements/Element.php @@ -2,7 +2,7 @@ abstract class Element { - protected $attributes = array(); + protected $attributes = []; protected function setAttribute($attribute, $value = null) { @@ -109,9 +109,9 @@ protected function renderAttributes() public function __call($method, $params) { - $params = count($params) ? $params : array($method); - $params = array_merge(array($method), $params); - call_user_func_array(array($this, 'attribute'), $params); + $params = count($params) ? $params : [$method]; + $params = array_merge([$method], $params); + call_user_func_array([$this, 'attribute'], $params); return $this; } } diff --git a/src/AdamWathan/Form/Elements/Email.php b/src/AdamWathan/Form/Elements/Email.php index 01f293d..ff974e6 100644 --- a/src/AdamWathan/Form/Elements/Email.php +++ b/src/AdamWathan/Form/Elements/Email.php @@ -2,7 +2,7 @@ class Email extends Text { - protected $attributes = array( + protected $attributes = [ 'type' => 'email', - ); + ]; } diff --git a/src/AdamWathan/Form/Elements/File.php b/src/AdamWathan/Form/Elements/File.php index 450c916..394d354 100644 --- a/src/AdamWathan/Form/Elements/File.php +++ b/src/AdamWathan/Form/Elements/File.php @@ -2,7 +2,7 @@ class File extends Input { - protected $attributes = array( + protected $attributes = [ 'type' => 'file', - ); + ]; } diff --git a/src/AdamWathan/Form/Elements/FormOpen.php b/src/AdamWathan/Form/Elements/FormOpen.php index 47cc36e..238d7b7 100644 --- a/src/AdamWathan/Form/Elements/FormOpen.php +++ b/src/AdamWathan/Form/Elements/FormOpen.php @@ -2,10 +2,10 @@ class FormOpen extends Element { - protected $attributes = array( + protected $attributes = [ 'method' => 'POST', 'action' => '', - ); + ]; protected $token; protected $hiddenMethod; diff --git a/src/AdamWathan/Form/Elements/Hidden.php b/src/AdamWathan/Form/Elements/Hidden.php index 56534cb..0e3520b 100644 --- a/src/AdamWathan/Form/Elements/Hidden.php +++ b/src/AdamWathan/Form/Elements/Hidden.php @@ -2,7 +2,7 @@ class Hidden extends Input { - protected $attributes = array( + protected $attributes = [ 'type' => 'hidden', - ); + ]; } diff --git a/src/AdamWathan/Form/Elements/Password.php b/src/AdamWathan/Form/Elements/Password.php index 91ded22..05b33be 100644 --- a/src/AdamWathan/Form/Elements/Password.php +++ b/src/AdamWathan/Form/Elements/Password.php @@ -2,7 +2,7 @@ class Password extends Text { - protected $attributes = array( + protected $attributes = [ 'type' => 'password', - ); + ]; } diff --git a/src/AdamWathan/Form/Elements/RadioButton.php b/src/AdamWathan/Form/Elements/RadioButton.php index 4619e82..b1dfb39 100644 --- a/src/AdamWathan/Form/Elements/RadioButton.php +++ b/src/AdamWathan/Form/Elements/RadioButton.php @@ -2,9 +2,9 @@ class RadioButton extends Checkbox { - protected $attributes = array( + protected $attributes = [ 'type' => 'radio', - ); + ]; public function __construct($name, $value = null) { diff --git a/src/AdamWathan/Form/Elements/Select.php b/src/AdamWathan/Form/Elements/Select.php index 0ed36bd..056a548 100644 --- a/src/AdamWathan/Form/Elements/Select.php +++ b/src/AdamWathan/Form/Elements/Select.php @@ -2,11 +2,10 @@ class Select extends FormControl { - private $options; private $selected; - public function __construct($name, $options = array()) + public function __construct($name, $options = []) { $this->setName($name); $this->setOptions($options); diff --git a/src/AdamWathan/Form/Elements/Text.php b/src/AdamWathan/Form/Elements/Text.php index c8fdd4f..deb891c 100644 --- a/src/AdamWathan/Form/Elements/Text.php +++ b/src/AdamWathan/Form/Elements/Text.php @@ -2,10 +2,9 @@ class Text extends Input { - - protected $attributes = array( + protected $attributes = [ 'type' => 'text', - ); + ]; public function placeholder($placeholder) { diff --git a/src/AdamWathan/Form/Elements/TextArea.php b/src/AdamWathan/Form/Elements/TextArea.php index 23029cf..30eefe8 100644 --- a/src/AdamWathan/Form/Elements/TextArea.php +++ b/src/AdamWathan/Form/Elements/TextArea.php @@ -2,12 +2,11 @@ class TextArea extends FormControl { - - protected $attributes = array( + protected $attributes = [ 'name' => '', 'rows' => 10, 'cols' => 50, - ); + ]; protected $value; diff --git a/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php b/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php index 9e7327c..1cd0f49 100644 --- a/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php +++ b/src/AdamWathan/Form/ErrorStore/IlluminateErrorStore.php @@ -43,6 +43,6 @@ protected function getErrors() protected function transformKey($key) { - return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key); + return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key); } } diff --git a/src/AdamWathan/Form/FormBuilder.php b/src/AdamWathan/Form/FormBuilder.php index 1c0927e..032f8e9 100644 --- a/src/AdamWathan/Form/FormBuilder.php +++ b/src/AdamWathan/Form/FormBuilder.php @@ -153,7 +153,7 @@ public function submit($value = 'Submit') return $submit; } - public function select($name, $options = array()) + public function select($name, $options = []) { $select = new Select($name, $options); @@ -274,7 +274,7 @@ protected function unbindModel() public function selectMonth($name) { - $options = array( + $options = [ "1" => "January", "2" => "February", "3" => "March", @@ -287,13 +287,13 @@ public function selectMonth($name) "10" => "October", "11" => "November", "12" => "December", - ); + ]; return $this->select($name, $options); } protected function transformKey($key) { - return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key); + return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key); } } diff --git a/src/AdamWathan/Form/FormServiceProvider.php b/src/AdamWathan/Form/FormServiceProvider.php index 3c0754c..76781c7 100644 --- a/src/AdamWathan/Form/FormServiceProvider.php +++ b/src/AdamWathan/Form/FormServiceProvider.php @@ -58,6 +58,6 @@ protected function registerFormBuilder() */ public function provides() { - return array('adamwathan.form'); + return ['adamwathan.form']; } } diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 688ff4e..308f4b6 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -22,73 +22,73 @@ public function testFormBuilderCanBeCreated() public function testFormOpen() { $expected = '
'; - $result = (string)$this->form->open(); + $result = (string) $this->form->open(); $this->assertEquals($expected, $result); } public function testCanCloseForm() { $expected = '
'; - $result = (string)$this->form->close(); + $result = (string) $this->form->close(); $this->assertEquals($expected, $result); } public function testTextBox() { $expected = ''; - $result = (string)$this->form->text('email'); + $result = (string) $this->form->text('email'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->text('first_name'); + $result = (string) $this->form->text('first_name'); $this->assertEquals($expected, $result); } public function testPassword() { $expected = ''; - $result = (string)$this->form->password('password'); + $result = (string) $this->form->password('password'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->password('password_confirmed'); + $result = (string) $this->form->password('password_confirmed'); $this->assertEquals($expected, $result); } public function testCheckbox() { $expected = ''; - $result = (string)$this->form->checkbox('terms'); + $result = (string) $this->form->checkbox('terms'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('terms', 'agree'); + $result = (string) $this->form->checkbox('terms', 'agree'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('terms')->value('agree'); + $result = (string) $this->form->checkbox('terms')->value('agree'); $this->assertEquals($expected, $result); } public function testRadio() { $expected = ''; - $result = (string)$this->form->radio('terms'); + $result = (string) $this->form->radio('terms'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->radio('terms', 'agree'); + $result = (string) $this->form->radio('terms', 'agree'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->radio('terms')->value('agree'); + $result = (string) $this->form->radio('terms')->value('agree'); $this->assertEquals($expected, $result); } public function testSubmit() { $expected = ''; - $result = (string)$this->form->submit('Sign In'); + $result = (string) $this->form->submit('Sign In'); $this->assertEquals($expected, $result); } @@ -97,7 +97,7 @@ public function testSubmit() */ public function testButton($value, $name, $expected) { - $result = (string)$this->form->button($value, $name); + $result = (string) $this->form->button($value, $name); $this->assertEquals($expected, $result); } @@ -112,33 +112,33 @@ public function buttonProvider() public function testSelect() { $expected = ''; - $result = (string)$this->form->select('color', ['red' => 'Red', 'blue' => 'Blue']); + $result = (string) $this->form->select('color', ['red' => 'Red', 'blue' => 'Blue']); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); + $result = (string) $this->form->select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $this->assertEquals($expected, $result); } public function testTextArea() { $expected = ''; - $result = (string)$this->form->textarea('bio'); + $result = (string) $this->form->textarea('bio'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->textarea('description'); + $result = (string) $this->form->textarea('description'); $this->assertEquals($expected, $result); } public function testLabel() { $expected = ''; - $result = (string)$this->form->label('Email'); + $result = (string) $this->form->label('Email'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->label('First Name'); + $result = (string) $this->form->label('First Name'); $this->assertEquals($expected, $result); } @@ -151,7 +151,7 @@ public function testRenderTextWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->text('title'); + $result = (string) $this->form->text('title'); $this->assertEquals($expected, $result); } @@ -164,11 +164,11 @@ public function testRenderCheckboxWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->checkbox('terms', 'agree'); + $result = (string) $this->form->checkbox('terms', 'agree'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('terms')->value('agree'); + $result = (string) $this->form->checkbox('terms')->value('agree'); $this->assertEquals($expected, $result); } @@ -181,15 +181,15 @@ public function testRenderCheckboxArrayWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->checkbox('favourite_foods[]', 'fish'); + $result = (string) $this->form->checkbox('favourite_foods[]', 'fish'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('favourite_foods[]', 'tofu'); + $result = (string) $this->form->checkbox('favourite_foods[]', 'tofu'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('favourite_foods[]', 'chips'); + $result = (string) $this->form->checkbox('favourite_foods[]', 'chips'); $this->assertEquals($expected, $result); } @@ -202,11 +202,11 @@ public function testRenderRadioWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->radio('color', 'green'); + $result = (string) $this->form->radio('color', 'green'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->radio('color')->value('green'); + $result = (string) $this->form->radio('color')->value('green'); $this->assertEquals($expected, $result); } @@ -219,7 +219,7 @@ public function testExplicitUncheckOnCheckboxTakesPrecedenceOverOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->checkbox('terms', 'agree')->uncheck(); + $result = (string) $this->form->checkbox('terms', 'agree')->uncheck(); $this->assertEquals($expected, $result); } @@ -232,7 +232,7 @@ public function testExplicitUncheckOnRadioTakesPrecedenceOverOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->radio('color', 'green')->uncheck(); + $result = (string) $this->form->radio('color', 'green')->uncheck(); $this->assertEquals($expected, $result); } @@ -245,7 +245,7 @@ public function testExplicitCheckOnCheckboxTakesPrecedenceOverOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->checkbox('terms', 'agree')->check(); + $result = (string) $this->form->checkbox('terms', 'agree')->check(); $this->assertEquals($expected, $result); } @@ -258,14 +258,14 @@ public function testExplicitCheckOnRadioTakesPrecedenceOverOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->radio('color', 'green')->check(); + $result = (string) $this->form->radio('color', 'green')->check(); $this->assertEquals($expected, $result); } public function testRenderCheckboxAgainstBinaryZero() { $expected = ''; - $result = (string)$this->form->checkbox('boolean', 0); + $result = (string) $this->form->checkbox('boolean', 0); $this->assertEquals($expected, $result); } @@ -278,14 +278,14 @@ public function testRenderCheckboxAgainstBinaryOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->checkbox('agree_to_terms', 1); + $result = (string) $this->form->checkbox('agree_to_terms', 1); $this->assertEquals($expected, $result); } public function testRenderRadioAgainstBinaryZero() { $expected = ''; - $result = (string)$this->form->radio('boolean', 0); + $result = (string) $this->form->radio('boolean', 0); $this->assertEquals($expected, $result); } @@ -298,11 +298,11 @@ public function testRenderSelectWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->select('color', ['red' => 'Red', 'blue' => 'Blue']); + $result = (string) $this->form->select('color', ['red' => 'Red', 'blue' => 'Blue']); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->select('color')->options(['red' => 'Red', 'blue' => 'Blue']); + $result = (string) $this->form->select('color')->options(['red' => 'Red', 'blue' => 'Blue']); $this->assertEquals($expected, $result); } @@ -319,7 +319,7 @@ public function testRenderMultipleSelectWithOldInput() $expected .= ''; $expected .= ''; $expected .= ''; - $result = (string)$this->form->select('favourite_foods', ['fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'])->multiple(); + $result = (string) $this->form->select('favourite_foods', ['fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'])->multiple(); $this->assertEquals($expected, $result); } @@ -332,7 +332,7 @@ public function testRenderTextAreaWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->textarea('bio'); + $result = (string) $this->form->textarea('bio'); $this->assertEquals($expected, $result); } @@ -345,14 +345,14 @@ public function testRenderingTextAreaWithOldInputEscapesDangerousCharacters() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->textarea('bio'); + $result = (string) $this->form->textarea('bio'); $this->assertEquals($expected, $result); } public function testNoErrorStoreReturnsNull() { $expected = ''; - $result = (string)$this->form->getError('email'); + $result = (string) $this->form->getError('email'); $this->assertEquals($expected, $result); } @@ -416,44 +416,44 @@ public function testFormattedErrorMessageReturnsNothingIfNoError() public function testHidden() { $expected = ''; - $result = (string)$this->form->hidden('secret'); + $result = (string) $this->form->hidden('secret'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->hidden('token'); + $result = (string) $this->form->hidden('token'); $this->assertEquals($expected, $result); } public function testFile() { $expected = ''; - $result = (string)$this->form->file('photo'); + $result = (string) $this->form->file('photo'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->file('document'); + $result = (string) $this->form->file('document'); $this->assertEquals($expected, $result); } public function testDate() { $expected = ''; - $result = (string)$this->form->date('date_of_birth'); + $result = (string) $this->form->date('date_of_birth'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->date('start_date'); + $result = (string) $this->form->date('start_date'); $this->assertEquals($expected, $result); } public function testEmail() { $expected = ''; - $result = (string)$this->form->email('email'); + $result = (string) $this->form->email('email'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->email('alternate_email'); + $result = (string) $this->form->email('alternate_email'); $this->assertEquals($expected, $result); } @@ -466,7 +466,7 @@ public function testRenderDateWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->date('date_of_birth'); + $result = (string) $this->form->date('date_of_birth'); $this->assertEquals($expected, $result); } @@ -479,7 +479,7 @@ public function testRenderEmailWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->email('email'); + $result = (string) $this->form->email('email'); $this->assertEquals($expected, $result); } @@ -492,7 +492,7 @@ public function testRenderHiddenWithOldInput() $this->form->setOldInputProvider($oldInput); $expected = ''; - $result = (string)$this->form->hidden('secret'); + $result = (string) $this->form->hidden('secret'); $this->assertEquals($expected, $result); } @@ -506,7 +506,7 @@ public function testCanRenderCsrfToken() $this->form->setToken('12345'); $expected = ''; - $result = (string)$this->form->token(); + $result = (string) $this->form->token(); $this->assertEquals($expected, $result); } @@ -514,7 +514,7 @@ public function testTokenIsRenderedAutomaticallyOnOpenIfSet() { $this->form->setToken('12345'); $expected = '
'; - $result = (string)$this->form->open(); + $result = (string) $this->form->open(); $this->assertEquals($expected, $result); } @@ -522,14 +522,14 @@ public function testTokenIsNotRenderedAutomaticallyOnOpenFormWithGetMethodIfSet( { $this->form->setToken('12345'); $expected = ''; - $result = (string)$this->form->open()->get(); + $result = (string) $this->form->open()->get(); $this->assertEquals($expected, $result); } public function testSelectMonth() { $expected = ''; - $result = (string)$this->form->selectMonth('month'); + $result = (string) $this->form->selectMonth('month'); $this->assertEquals($expected, $result); } @@ -543,7 +543,7 @@ public function testBindEmail() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->email('email'); + $result = (string) $this->form->email('email'); $this->assertEquals($expected, $result); } @@ -552,7 +552,7 @@ public function testBindText() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('first_name'); + $result = (string) $this->form->text('first_name'); $this->assertEquals($expected, $result); } @@ -561,7 +561,7 @@ public function testBindTextWithIntegerZero() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('number'); + $result = (string) $this->form->text('number'); $this->assertEquals($expected, $result); } @@ -570,7 +570,7 @@ public function testBindDate() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->date('date_of_birth'); + $result = (string) $this->form->date('date_of_birth'); $this->assertEquals($expected, $result); } @@ -579,7 +579,7 @@ public function testBindSelect() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->select('gender', ['male' => 'Male', 'female' => 'Female']); + $result = (string) $this->form->select('gender', ['male' => 'Male', 'female' => 'Female']); $this->assertEquals($expected, $result); } @@ -593,7 +593,7 @@ public function testBindMultipleSelect() $expected .= ''; $expected .= ''; $expected .= ''; - $result = (string)$this->form->select('favourite_foods', ['fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'])->multiple(); + $result = (string) $this->form->select('favourite_foods', ['fish' => 'Fish', 'tofu' => 'Tofu', 'chips' => 'Chips'])->multiple(); $this->assertEquals($expected, $result); } @@ -602,7 +602,7 @@ public function testBindHidden() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->hidden('last_name'); + $result = (string) $this->form->hidden('last_name'); $this->assertEquals($expected, $result); } @@ -616,7 +616,7 @@ public function testOldInputTakesPrecedenceOverBinding() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('first_name'); + $result = (string) $this->form->text('first_name'); $this->assertEquals($expected, $result); } @@ -625,7 +625,7 @@ public function testBindCheckbox() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->checkbox('terms', 'agree'); + $result = (string) $this->form->checkbox('terms', 'agree'); $this->assertEquals($expected, $result); } @@ -635,15 +635,15 @@ public function testBindCheckboxArray() $this->form->bind($object); $expected = ''; - $result = (string)$this->form->checkbox('favourite_foods[]', 'fish'); + $result = (string) $this->form->checkbox('favourite_foods[]', 'fish'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('favourite_foods[]', 'tofu'); + $result = (string) $this->form->checkbox('favourite_foods[]', 'tofu'); $this->assertEquals($expected, $result); $expected = ''; - $result = (string)$this->form->checkbox('favourite_foods[]', 'chips'); + $result = (string) $this->form->checkbox('favourite_foods[]', 'chips'); $this->assertEquals($expected, $result); } @@ -652,7 +652,7 @@ public function testValueTakesPrecedenceOverBinding() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('first_name')->value('Mike'); + $result = (string) $this->form->text('first_name')->value('Mike'); $this->assertEquals($expected, $result); } @@ -661,7 +661,7 @@ public function testExplicitUncheckOnCheckboxTakesPrecedenceOverBinding() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->radio('terms', 'agree')->uncheck(); + $result = (string) $this->form->radio('terms', 'agree')->uncheck(); $this->assertEquals($expected, $result); } @@ -670,7 +670,7 @@ public function testExplicitUncheckOnRadioTakesPrecedenceOverBinding() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->radio('color', 'green')->uncheck(); + $result = (string) $this->form->radio('color', 'green')->uncheck(); $this->assertEquals($expected, $result); } @@ -679,7 +679,7 @@ public function testExplicitCheckOnCheckboxTakesPrecedenceOverBinding() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->radio('terms', 'agree')->check(); + $result = (string) $this->form->radio('terms', 'agree')->check(); $this->assertEquals($expected, $result); } @@ -688,7 +688,7 @@ public function testExplicitCheckOnRadioTakesPrecedenceOverBinding() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->radio('color', 'green')->check(); + $result = (string) $this->form->radio('color', 'green')->check(); $this->assertEquals($expected, $result); } @@ -697,7 +697,7 @@ public function testBindUnsetProperty() $object = $this->getStubObject(); $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('not_set'); + $result = (string) $this->form->text('not_set'); $this->assertEquals($expected, $result); } @@ -706,7 +706,7 @@ public function testBindMagicProperty() $object = new MagicGetter; $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('not_set'); + $result = (string) $this->form->text('not_set'); $this->assertEquals($expected, $result); } @@ -715,7 +715,7 @@ public function testBindArray() $model = ['first_name' => 'John']; $this->form->bind($model); $expected = ''; - $result = (string)$this->form->text('first_name'); + $result = (string) $this->form->text('first_name'); $this->assertEquals($expected, $result); } @@ -725,7 +725,7 @@ public function testCloseUnbindsModel() $this->form->bind($object); $this->form->close(); $expected = ''; - $result = (string)$this->form->text('first_name'); + $result = (string) $this->form->text('first_name'); $this->assertEquals($expected, $result); } @@ -735,14 +735,14 @@ public function testAgainstXSSAttacksInBoundModels() $object->first_name = '" onmouseover="alert(\'xss\')'; $this->form->bind($object); $expected = ''; - $result = (string)$this->form->text('first_name'); + $result = (string) $this->form->text('first_name'); $this->assertEquals($expected, $result); } public function testRemoveClass() { $expected = ''; - $result = (string)$this->form->text('food')->addClass('sandwich pizza')->removeClass('sandwich')->removeClass('pizza'); + $result = (string) $this->form->text('food')->addClass('sandwich pizza')->removeClass('sandwich')->removeClass('pizza'); $this->assertEquals($expected, $result); } diff --git a/tests/FormOpenTest.php b/tests/FormOpenTest.php index ba212e8..9ebd893 100644 --- a/tests/FormOpenTest.php +++ b/tests/FormOpenTest.php @@ -112,7 +112,7 @@ public function testCanRenderCsrfToken() { $open = new FormOpen; $expected = ''; - $result = (string)$open->token('abc123'); + $result = (string) $open->token('abc123'); $this->assertEquals($expected, $result); } diff --git a/tests/InputContractTest.php b/tests/InputContractTest.php index 654734d..a2b0a9f 100644 --- a/tests/InputContractTest.php +++ b/tests/InputContractTest.php @@ -119,7 +119,7 @@ public function testCanBeCastToString() $text = $this->newTestSubjectInstance('email'); $expected = $text->render(); - $result = (string)$text; + $result = (string) $text; $message = 'Casting input element to string should return the rendered element'; $this->assertEquals($expected, $result, $message); } From c49d9e92a8a8bab38b65a6f4cd642ccd175596c7 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 19 Feb 2016 15:09:52 -0500 Subject: [PATCH 09/10] DHH wouldn't approve, because it's not Ruby. --- .../OldInput/IlluminateOldInputProvider.php | 2 +- tests/IlluminateErrorStoreTest.php | 4 +- tests/SelectTest.php | 88 +++++++++---------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php b/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php index 2208dff..4307cf5 100644 --- a/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php +++ b/src/AdamWathan/Form/OldInput/IlluminateOldInputProvider.php @@ -23,6 +23,6 @@ public function getOldInput($key) protected function transformKey($key) { - return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key); + return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key); } } diff --git a/tests/IlluminateErrorStoreTest.php b/tests/IlluminateErrorStoreTest.php index 50ceb1d..59c19b0 100644 --- a/tests/IlluminateErrorStoreTest.php +++ b/tests/IlluminateErrorStoreTest.php @@ -7,9 +7,9 @@ class IlluminateErrorStoreTest extends PHPUnit_Framework_TestCase { public function test_it_converts_array_keys_to_dot_notation() { - $errors = new MessageBag(array( + $errors = new MessageBag([ 'foo.bar' => 'Some error', - )); + ]); $session = Mockery::mock('Illuminate\Session\Store'); $session->shouldReceive('has')->with('errors')->andReturn(true); $session->shouldReceive('get')->with('errors')->andReturn($errors); diff --git a/tests/SelectTest.php b/tests/SelectTest.php index b1b0c93..19cedd2 100644 --- a/tests/SelectTest.php +++ b/tests/SelectTest.php @@ -21,13 +21,13 @@ protected function elementRegExp($attributes) public function testSelectCanBeCreatedWithOptions() { - $select = new Select('birth_year', array(1990, 1991, 1992)); + $select = new Select('birth_year', [1990, 1991, 1992]); $expected = ''; $result = $select->render(); $this->assertEquals($expected, $result); - $select = new Select('birth_year', array(2001, 2002, 2003)); + $select = new Select('birth_year', [2001, 2002, 2003]); $expected = ''; $result = $select->render(); @@ -36,13 +36,13 @@ public function testSelectCanBeCreatedWithOptions() public function testSelectCanBeCreatedWithKeyValueOptions() { - $select = new Select('color', array('red' => 'Red', 'blue' => 'Blue')); + $select = new Select('color', ['red' => 'Red', 'blue' => 'Blue']); $expected = ''; $result = $select->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; $result = $select->render(); @@ -51,14 +51,14 @@ public function testSelectCanBeCreatedWithKeyValueOptions() public function testCanAddOption() { - $select = new Select('color', array('red' => 'Red')); + $select = new Select('color', ['red' => 'Red']); $select->addOption('blue', 'Blue'); $expected = ''; $result = $select->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith')); + $select = new Select('fruit', ['apple' => 'Granny Smith']); $select->addOption('berry', 'Blueberry'); $expected = ''; $result = $select->render(); @@ -69,14 +69,14 @@ public function testCanAddOption() public function testCanSetOptions() { $select = new Select('color'); - $select->options(array('red' => 'Red', 'blue' => 'Blue')); + $select->options(['red' => 'Red', 'blue' => 'Blue']); $expected = ''; $result = $select->render(); $this->assertEquals($expected, $result); $select = new Select('fruit'); - $select->options(array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select->options(['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; $result = $select->render(); @@ -86,14 +86,14 @@ public function testCanSetOptions() public function testCanSetSelectedOption() { $select = new Select('color'); - $select->options(array('red' => 'Red', 'blue' => 'Blue')); + $select->options(['red' => 'Red', 'blue' => 'Blue']); $expected = ''; $result = $select->select('blue')->render(); $this->assertEquals($expected, $result); $select = new Select('fruit'); - $select->options(array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select->options(['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; $result = $select->select('apple')->render(); @@ -103,14 +103,14 @@ public function testCanSetSelectedOption() public function testCanSelectNumericKeys() { $select = new Select('fruit'); - $select->options(array('1' => 'Granny Smith', '2' => 'Blueberry')); + $select->options(['1' => 'Granny Smith', '2' => 'Blueberry']); $expected = ''; $result = $select->select('1')->render(); $this->assertEquals($expected, $result); $select = new Select('fruit'); - $select->options(array('1' => 'Granny Smith', '2' => 'Blueberry')); + $select->options(['1' => 'Granny Smith', '2' => 'Blueberry']); $expected = ''; $result = $select->select('2')->render(); @@ -119,25 +119,25 @@ public function testCanSelectNumericKeys() public function testCanSetDefaultOption() { - $select = new Select('color', array('red' => 'Red', 'blue' => 'Blue')); + $select = new Select('color', ['red' => 'Red', 'blue' => 'Blue']); $expected = ''; $result = $select->defaultValue('blue')->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; $result = $select->defaultValue('apple')->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; $result = $select->select('berry')->defaultValue('apple')->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; $result = $select->defaultValue('apple')->select('berry')->render(); @@ -146,43 +146,43 @@ public function testCanSetDefaultOption() public function testCanSetDefaultOptionMultiselect() { - $select = new Select('color', array('red' => 'Red', 'blue' => 'Blue')); + $select = new Select('color', ['red' => 'Red', 'blue' => 'Blue']); $expected = ''; - $result = $select->defaultValue(array('blue', 'red'))->render(); + $result = $select->defaultValue(['blue', 'red'])->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; - $result = $select->defaultValue(array('apple'))->render(); + $result = $select->defaultValue(['apple'])->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; - $result = $select->select('berry')->defaultValue(array('apple', 'berry'))->render(); + $result = $select->select('berry')->defaultValue(['apple', 'berry'])->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('apple' => 'Granny Smith', 'berry' => 'Blueberry')); + $select = new Select('fruit', ['apple' => 'Granny Smith', 'berry' => 'Blueberry']); $expected = ''; - $result = $select->defaultValue('apple')->select(array('berry'))->render(); + $result = $select->defaultValue('apple')->select(['berry'])->render(); $this->assertEquals($expected, $result); } public function testCanUseNestedOptions() { - $options = array( - 'Ontario' => array( + $options = [ + 'Ontario' => [ 'toronto' => 'Toronto', 'london' => 'London', - ), - 'Quebec' => array( + ], + 'Quebec' => [ 'montreal' => 'Montreal', 'quebec-city' => 'Quebec City', - ), - ); + ], + ]; $select = new Select('color', $options); $expected = ''; $result = $select->render(); @@ -192,16 +192,16 @@ public function testCanUseNestedOptions() public function testCanUseNestedOptionsWithoutKeys() { - $options = array( - 'Ontario' => array( + $options = [ + 'Ontario' => [ 'Toronto', 'London', - ), - 'Quebec' => array( + ], + 'Quebec' => [ 'Montreal', 'Quebec City', - ), - ); + ], + ]; $select = new Select('color', $options); $expected = ''; $result = $select->render(); @@ -211,14 +211,14 @@ public function testCanUseNestedOptionsWithoutKeys() public function testCanMixNestedAndUnnestedOptions() { - $options = array( + $options = [ 'toronto' => 'Toronto', 'london' => 'London', - 'Quebec' => array( + 'Quebec' => [ 'montreal' => 'Montreal', 'quebec-city' => 'Quebec City', - ), - ); + ], + ]; $select = new Select('color', $options); $expected = ''; $result = $select->render(); @@ -228,12 +228,12 @@ public function testCanMixNestedAndUnnestedOptions() public function testSelectCanBeCreatedWithIntegerKeyValueOptions() { - $select = new Select('color', array('0' => 'Red', '1' => 'Blue')); + $select = new Select('color', ['0' => 'Red', '1' => 'Blue']); $expected = ''; $result = $select->render(); $this->assertEquals($expected, $result); - $select = new Select('fruit', array('1' => 'Granny Smith', '0' => 'Blueberry')); + $select = new Select('fruit', ['1' => 'Granny Smith', '0' => 'Blueberry']); $expected = ''; $result = $select->render(); $this->assertEquals($expected, $result); @@ -256,9 +256,9 @@ public function testSelectCanBeMultiple() public function testCanSelectMultipleElementsInMultiselects() { - $select = new Select('color', array('red' => 'Red', 'blue' => 'Blue')); + $select = new Select('color', ['red' => 'Red', 'blue' => 'Blue']); $expected = ''; - $result = $select->multiple()->select(array('red', 'blue'))->render(); + $result = $select->multiple()->select(['red', 'blue'])->render(); $this->assertEquals($expected, $result); } From c5a55bb424f5f1b1a81ea101509d98d99ae2dec1 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 19 Feb 2016 15:15:42 -0500 Subject: [PATCH 10/10] Adam with the one-liners. --- tests/IlluminateErrorStoreTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/IlluminateErrorStoreTest.php b/tests/IlluminateErrorStoreTest.php index 59c19b0..7e5d025 100644 --- a/tests/IlluminateErrorStoreTest.php +++ b/tests/IlluminateErrorStoreTest.php @@ -7,9 +7,7 @@ class IlluminateErrorStoreTest extends PHPUnit_Framework_TestCase { public function test_it_converts_array_keys_to_dot_notation() { - $errors = new MessageBag([ - 'foo.bar' => 'Some error', - ]); + $errors = new MessageBag(['foo.bar' => 'Some error']); $session = Mockery::mock('Illuminate\Session\Store'); $session->shouldReceive('has')->with('errors')->andReturn(true); $session->shouldReceive('get')->with('errors')->andReturn($errors);