From 0b296a592dbc7c810e6da33c7af33a312dc2b072 Mon Sep 17 00:00:00 2001 From: codisart Date: Fri, 21 Jul 2017 12:34:13 +0200 Subject: [PATCH 1/2] issue-125 - add unit test proving undefined index error --- test/BetweenTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/BetweenTest.php b/test/BetweenTest.php index 478c12c96..bf0197d2b 100644 --- a/test/BetweenTest.php +++ b/test/BetweenTest.php @@ -271,6 +271,15 @@ public function constructBetweenValidatorInvalidDataProvider() [ ['max' => 5], ], + [ + ['min' => 0, 'inclusive' => true], + ], + [ + ['min' => 0, 'foo' => 'bar'], + ], + [ + ['bar' => 'foo', 'foo' => 'bar'], + ], ]; } From 8a80fc8611ab4c2f8ae6ec35eb6acc3ebb2a724c Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 31 Jul 2017 14:49:14 -0500 Subject: [PATCH 2/2] Provides fix for #125 Builds on the tests given in #183, adding more cases, and providing a fix for the issue. --- src/Between.php | 12 +++++++----- test/BetweenTest.php | 22 +++++++--------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Between.php b/src/Between.php index 05a74bcca..28dcd6065 100644 --- a/src/Between.php +++ b/src/Between.php @@ -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( diff --git a/test/BetweenTest.php b/test/BetweenTest.php index bf0197d2b..55ee4e7ce 100644 --- a/test/BetweenTest.php +++ b/test/BetweenTest.php @@ -265,21 +265,13 @@ public function testMissingMinOrMax(array $args) public function constructBetweenValidatorInvalidDataProvider() { return [ - [ - ['min' => 1], - ], - [ - ['max' => 5], - ], - [ - ['min' => 0, 'inclusive' => true], - ], - [ - ['min' => 0, 'foo' => 'bar'], - ], - [ - ['bar' => 'foo', 'foo' => 'bar'], - ], + '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']], ]; }