Skip to content

Commit

Permalink
Merge pull request #442 from Great-Antique/master
Browse files Browse the repository at this point in the history
Fix exception message on range validation
  • Loading branch information
koenpunt committed Dec 6, 2014
2 parents f1c0f9d + 241e503 commit 685f95d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Validations.php
Expand Up @@ -494,7 +494,7 @@ public function validates_length_of($attrs)
$range = $options[$range_options[0]];

if (!(Utils::is_a('range', $range)))
throw new ValidationsArgumentError("$range_option must be an array composing a range of numbers with key [0] being less than key [1]");
throw new ValidationsArgumentError("$range_options[0] must be an array composing a range of numbers with key [0] being less than key [1]");
$range_options = array('minimum', 'maximum');
$attr['minimum'] = $range[0];
$attr['maximum'] = $range[1];
Expand Down Expand Up @@ -814,7 +814,7 @@ public function full_messages()
* # )
* </code>
*
* @param array $closure Closure to fetch the errors in some other format (optional)
* @param callable $closure Closure to fetch the errors in some other format (optional)
* This closure has the signature function($attribute, $message)
* and is called for each available error message.
* @return array
Expand Down
25 changes: 25 additions & 0 deletions test/ValidatesLengthOfTest.php
Expand Up @@ -199,6 +199,31 @@ public function test_signed_integer_as_impossible_within_option()
$this->fail('An expected exception has not be raised.');
}

public function test_not_array_as_impossible_range_option()
{
BookLength::$validates_length_of[0]['within'] = 'string';
$book = new BookLength;
$book->name = '123';
try {
$book->save();
} catch (ActiveRecord\ValidationsArgumentError $e) {
$this->assert_equals('within must be an array composing a range of numbers with key [0] being less than key [1]', $e->getMessage());
}

$this->set_up();
BookLength::$validates_length_of[0]['in'] = 'string';
$book = new BookLength;
$book->name = '123';
try {
$book->save();
} catch (ActiveRecord\ValidationsArgumentError $e) {
$this->assert_equals('in must be an array composing a range of numbers with key [0] being less than key [1]', $e->getMessage());
return;
}

$this->fail('An expected exception has not be raised.');
}

public function test_signed_integer_as_impossible_is_option()
{
BookLength::$validates_length_of[0]['is'] = -8;
Expand Down

0 comments on commit 685f95d

Please sign in to comment.