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

Commit 44b33cc

Browse files
committed
Merge branch 'feature/187' into develop
Close #187 Close #183 Fixes #125
2 parents 39bd051 + 2f677bc commit 44b33cc

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ All notable changes to this project will be documented in this file, in reverse
2929
zend-session requirement (during development, and in the suggestions) to 2.8+,
3030
to ensure compatibility with the upcoming PHP 7.2 release.
3131

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

3441
- Nothing.

src/Between.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ public function __construct($options = null)
9090
$options = $temp;
9191
}
9292

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

99-
if (is_numeric($options['min']) && is_numeric($options['max'])) {
97+
if ((isset($options['min']) && is_numeric($options['min']))
98+
&& (isset($options['max']) && is_numeric($options['max']))
99+
) {
100100
$this->numeric = true;
101-
} elseif (is_string($options['min']) && is_string($options['max'])) {
101+
} elseif ((isset($options['min']) && is_string($options['min']))
102+
&& (isset($options['max']) && is_string($options['max']))
103+
) {
102104
$this->numeric = false;
103105
} else {
104106
throw new Exception\InvalidArgumentException(

test/BetweenTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,13 @@ public function testMissingMinOrMax(array $args)
265265
public function constructBetweenValidatorInvalidDataProvider()
266266
{
267267
return [
268-
[
269-
['min' => 1],
270-
],
271-
[
272-
['max' => 5],
273-
],
268+
'only-min' => [['min' => 1]],
269+
'only-max' => [['max' => 5]],
270+
'min-inclusive' => [['min' => 0, 'inclusive' => true]],
271+
'max-inclusive' => [['max' => 5, 'inclusive' => true]],
272+
'min-undefined' => [['min' => 0, 'foo' => 'bar']],
273+
'max-undefined' => [['max' => 5, 'foo' => 'bar']],
274+
'no-min-or-max' => [['bar' => 'foo', 'foo' => 'bar']],
274275
];
275276
}
276277

0 commit comments

Comments
 (0)