Skip to content
Permalink
Browse files

fix grammar

add exception throw on bad format
  • Loading branch information...
Graziel committed Apr 8, 2016
1 parent 219f22a commit 35c51bb5a53f820964fbecf117566105d5eb3004
Showing with 18 additions and 3 deletions.
  1. +6 −3 src/Validation/Validator.php
  2. +12 −0 tests/TestCase/Validation/ValidatorTest.php
@@ -428,8 +428,8 @@ public function remove($field, $rule = null)
* - `mode` individual mode for field
* - `message` individual error message for field
*
* You can also set mode and message for all passed fields, the individual settings
* takes precedence over group setting.
* You can also set mode and message for all passed fields, the individual setting
* takes precedence over group settings.
*
* @param string|array $field the name of the field
* @param bool|string|callable $mode Valid values are true, false, 'create', 'update'.
@@ -450,10 +450,13 @@ public function requirePresence($field, $mode = true, $message = null)
}
foreach ($field as $fieldName => $setting) {
if (is_string($setting)) {
if (is_string($setting) && is_int($fieldName)) {
$fieldName = $setting;
$setting = [];
}
if (!is_array($setting)) {
throw new InvalidArgumentException(sprintf('Invalid field "%s" setting, must be an array.', $fieldName));
}
$setting += [
'mode' => $mode,
'message' => $message
@@ -217,6 +217,18 @@ public function testRequirePresenceAsArray()
$this->assertTrue($validator->field('subject')->isPresenceRequired());
}
/**
* Tests the requirePresence failure case
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testRequirePresenceAsArrayFailure()
{
$validator = new Validator();
$validator->requirePresence(['title' => 'derp', 'created' => false]);
}
/**
* Tests the requirePresence method when passing a callback
*

0 comments on commit 35c51bb

Please sign in to comment.
You can’t perform that action at this time.