Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormContext error() should return array with error names as keys. #13250

Merged
merged 1 commit into from May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/View/Form/FormContext.php
Expand Up @@ -226,6 +226,6 @@ public function hasError($field)
*/
public function error($field)
{
return array_values((array)Hash::get($this->_form->getErrors(), $field, []));
return (array)Hash::get($this->_form->getErrors(), $field, []);
}
}
8 changes: 4 additions & 4 deletions tests/TestCase/View/Form/FormContextTest.php
Expand Up @@ -295,9 +295,9 @@ public function testError()

$context = new FormContext($this->request, ['entity' => $form]);
$this->assertEquals([], $context->error('empty'));
$this->assertEquals(['The provided value is invalid'], $context->error('email'));
$this->assertEquals(['The provided value is invalid'], $context->error('name'));
$this->assertEquals(['The provided value is invalid'], $context->error('pass.password'));
$this->assertEquals(['format' => 'The provided value is invalid'], $context->error('email'));
$this->assertEquals(['length' => 'The provided value is invalid'], $context->error('name'));
$this->assertEquals(['length' => 'The provided value is invalid'], $context->error('pass.password'));
$this->assertEquals([], $context->error('Alias.name'));
$this->assertEquals([], $context->error('nope.nope'));

Expand All @@ -307,7 +307,7 @@ public function testError()
$form->validate([]);
$context = new FormContext($this->request, ['entity' => $form]);
$this->assertEquals(
['should be an array, not a string'],
['_required' => 'should be an array, not a string'],
$context->error('key'),
'This test should not produce a PHP warning from array_values().'
);
Expand Down