diff --git a/src/View/Form/ArrayContext.php b/src/View/Form/ArrayContext.php index c5831f2fb9e..d2c0d6fb3a9 100644 --- a/src/View/Form/ArrayContext.php +++ b/src/View/Form/ArrayContext.php @@ -154,12 +154,12 @@ public function hasError($field) { * Get the errors for a given field * * @param string $field A dot separated path to check errors on. - * @return mixed Either a string or an array of errors. Null - * will be returned when the field path is undefined. + * @return array An array of errors, an empty array will be returned when the + * context has no errors. */ public function error($field) { if (empty($this->_context['errors'])) { - return null; + return []; } return Hash::get($this->_context['errors'], $field); } diff --git a/src/View/Form/EntityContext.php b/src/View/Form/EntityContext.php index 5f27d988937..f0edd9b8412 100644 --- a/src/View/Form/EntityContext.php +++ b/src/View/Form/EntityContext.php @@ -301,19 +301,17 @@ public function hasError($field) { return !empty($errors); } - /** * Get the errors for a given field * * @param string $field A dot separated path to check errors on. - * @return array|null Either an array of errors. Null will be returned when the - * field path is undefined or there is no error. + * @return array An array of errors. */ public function error($field) { $parts = explode('.', $field); list($entity, $prop) = $this->_getEntity($parts); if (!$entity) { - return false; + return []; } return $entity->errors(array_pop($parts)); } diff --git a/tests/TestCase/View/Form/ArrayContextTest.php b/tests/TestCase/View/Form/ArrayContextTest.php index 93d6b9a1f3d..2808821ac11 100644 --- a/tests/TestCase/View/Form/ArrayContextTest.php +++ b/tests/TestCase/View/Form/ArrayContextTest.php @@ -153,6 +153,9 @@ public function testAttributes() { * @return void */ public function testError() { + $context = new ArrayContext($this->request, []); + $this->assertEquals([], $context->error('Comments.empty')); + $context = new ArrayContext($this->request, [ 'errors' => [ 'Comments' => [