From 8f364b89a8a3a369cdac596e950f8a1d836560d7 Mon Sep 17 00:00:00 2001 From: Lane Roberts Date: Thu, 18 Sep 2014 11:07:38 -0500 Subject: [PATCH 1/3] Add test to exhibit error behavior --- tests/Valitron/ValidateTest.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 16bed82..7fce178 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -578,6 +578,32 @@ class ValidateTest extends BaseTestCase $this->assertTrue($v->validate()); } + public function testDateWarningsWithObjectParams() + { + $v = new Validator(array('startDate' => '2013-01-27', 'endDate' => '2013-05-08')); + $v->rule( + 'date', + [ + 'startDate', + 'endDate' + ] + ); + + $v->rule( + 'dateBefore', + 'endDate', + new DateTime('2013-04-08') + )->label('End date')->message('{field} must be before the end of the fiscal year, %s.'); + + $v->rule( + 'dateAfter', + 'startDate', + new DateTime('2013-02-17') + )->label('Start date')->message('{field} must be after the beginning of the fiscal year, %s.'); + + $this->assertFalse($v->validate()); + } + public function testDateBeforeInvalid() { $v = new Validator(array('date' => '2013-01-27')); From f8f1c0061bcfd5c64fd8d60c6487efa70c3b1130 Mon Sep 17 00:00:00 2001 From: Lane Roberts Date: Thu, 18 Sep 2014 10:39:25 -0500 Subject: [PATCH 2/3] Fix 'Illegal offset type in isset or empty' warning when a param is an object. Params can be any data type, but keys can only be integers or strings. --- src/Valitron/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index e6b7e16..08b6e58 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -992,7 +992,7 @@ class Validator $i = 1; foreach ($params as $k => $v) { $tag = '{field'. $i .'}'; - $label = isset($params[$k]) && !is_array($params[$k]) && isset($this->_labels[$params[$k]]) ? $this->_labels[$params[$k]] : $tag; + $label = isset($params[$k]) && (is_numeric($params[$k]) || is_string($params[$k])) && isset($this->_labels[$params[$k]]) ? $this->_labels[$params[$k]] : $tag; $msg = str_replace($tag, $label, $msg); $i++; } From 282f4a6ac3b172af7f9bed1c6d1c32f608c98579 Mon Sep 17 00:00:00 2001 From: Lane Roberts Date: Thu, 18 Sep 2014 11:32:30 -0500 Subject: [PATCH 3/3] PHP 5.3 compatibility in array syntax --- tests/Valitron/ValidateTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 7fce178..385190c 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -583,10 +583,10 @@ class ValidateTest extends BaseTestCase $v = new Validator(array('startDate' => '2013-01-27', 'endDate' => '2013-05-08')); $v->rule( 'date', - [ + array( 'startDate', 'endDate' - ] + ) ); $v->rule(