Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/187' into develop
Browse files Browse the repository at this point in the history
Close #187
Close #183
Fixes #125
  • Loading branch information
weierophinney committed Aug 14, 2017
2 parents 39bd051 + 2f677bc commit 44b33cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ All notable changes to this project will be documented in this file, in reverse
zend-session requirement (during development, and in the suggestions) to 2.8+,
to ensure compatibility with the upcoming PHP 7.2 release.

- [#187](https://github.com/zendframework/zend-validator/pull/187) updates the
`Between` validator to **require** that both a `min` and a `max` value are
provided to the constructor, and that both are of the same type (both
integer/float values and/or both string values). This fixes issues that could
previously occur when one or the other was not set, but means an exception
will now be raised during instantiation (versus runtime during `isValid()`).

### Deprecated

- Nothing.
Expand Down
12 changes: 7 additions & 5 deletions src/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,17 @@ public function __construct($options = null)
$options = $temp;
}

if (count($options) !== 2
&& (! array_key_exists('min', $options) || ! array_key_exists('max', $options))
) {
if (! array_key_exists('min', $options) || ! array_key_exists('max', $options)) {
throw new Exception\InvalidArgumentException("Missing option: 'min' and 'max' have to be given");
}

if (is_numeric($options['min']) && is_numeric($options['max'])) {
if ((isset($options['min']) && is_numeric($options['min']))
&& (isset($options['max']) && is_numeric($options['max']))
) {
$this->numeric = true;
} elseif (is_string($options['min']) && is_string($options['max'])) {
} elseif ((isset($options['min']) && is_string($options['min']))
&& (isset($options['max']) && is_string($options['max']))
) {
$this->numeric = false;
} else {
throw new Exception\InvalidArgumentException(
Expand Down
13 changes: 7 additions & 6 deletions test/BetweenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ public function testMissingMinOrMax(array $args)
public function constructBetweenValidatorInvalidDataProvider()
{
return [
[
['min' => 1],
],
[
['max' => 5],
],
'only-min' => [['min' => 1]],
'only-max' => [['max' => 5]],
'min-inclusive' => [['min' => 0, 'inclusive' => true]],
'max-inclusive' => [['max' => 5, 'inclusive' => true]],
'min-undefined' => [['min' => 0, 'foo' => 'bar']],
'max-undefined' => [['max' => 5, 'foo' => 'bar']],
'no-min-or-max' => [['bar' => 'foo', 'foo' => 'bar']],
];
}

Expand Down

0 comments on commit 44b33cc

Please sign in to comment.