Skip to content

Commit

Permalink
Move error to case switch.
Browse files Browse the repository at this point in the history
Move the error closer to the happy paths, and remove a test that is
redundant.

Refs #9189
  • Loading branch information
markstory committed Aug 6, 2016
1 parent 5902079 commit 77e0bfa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
9 changes: 4 additions & 5 deletions src/View/Helper/FormHelper.php
Expand Up @@ -1024,10 +1024,6 @@ public function input($fieldName, array $options = [])
$options = $this->_parseOptions($fieldName, $options);
$options += ['id' => $this->_domId($fieldName)];

if (strtolower($options['type']) === 'input') {
throw new RuntimeException(sprintf('Invalid type "input" used for field "%s"', $fieldName));
}

$templater = $this->templater();
$newTemplates = $options['templates'];

Expand Down Expand Up @@ -1140,7 +1136,7 @@ protected function _inputContainerTemplate($options)
*/
protected function _getInput($fieldName, $options)
{
switch ($options['type']) {
switch (strtolower($options['type'])) {
case 'select':
$opts = $options['options'];
unset($options['options']);
Expand All @@ -1156,6 +1152,9 @@ protected function _getInput($fieldName, $options)
unset($options['options']);

return $this->multiCheckbox($fieldName, $opts, $options);
case 'input':
throw new RuntimeException("Invalid type 'input' used for field '$fieldName'");

default:
return $this->{$options['type']}($fieldName, $options);
}
Expand Down
14 changes: 2 additions & 12 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -3683,24 +3683,14 @@ public function testInputMagicSelectForTypeNumber()
* Test invalid 'input' type option to input() function.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Invalid type 'input' used for field 'text'
* @return void
*/
public function testInvalidInputTypeOptionLowercase()
public function testInvalidInputTypeOption()
{
$this->Form->input('text', ['type' => 'input']);
}

/**
* Test invalid 'Input' type option to input() function.
*
* @expectedException \RuntimeException
* @return void
*/
public function testInvalidInputTypeOptionUppercase()
{
$this->Form->input('text', ['type' => 'Input']);
}

/**
* Test that magic input() selects can easily be converted into radio types without error.
*
Expand Down

0 comments on commit 77e0bfa

Please sign in to comment.