Skip to content

Commit 758b805

Browse files
Add test for max and min validation rules (#44444)
1 parent 92d6509 commit 758b805

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Validation/ValidationValidatorTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,12 +2559,28 @@ public function testValidateMin()
25592559
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Min:3']);
25602560
$this->assertFalse($v->passes());
25612561

2562+
// an equal value qualifies.
2563+
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Min:3']);
2564+
$this->assertTrue($v->passes());
2565+
25622566
$v = new Validator($trans, ['foo' => 'anc'], ['foo' => 'Min:3']);
25632567
$this->assertTrue($v->passes());
25642568

25652569
$v = new Validator($trans, ['foo' => '2'], ['foo' => 'Numeric|Min:3']);
25662570
$this->assertFalse($v->passes());
25672571

2572+
// '2.001' is considered as a float when the "Numeric" rule exists.
2573+
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Numeric|Min:3']);
2574+
$this->assertFalse($v->passes());
2575+
2576+
// '2.001' is a string of length 5 in absence of the "Numeric" rule.
2577+
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Min:3']);
2578+
$this->assertTrue($v->passes());
2579+
2580+
// '20' is a string of length 2 in absence of the "Numeric" rule.
2581+
$v = new Validator($trans, ['foo' => '20'], ['foo' => 'Min:3']);
2582+
$this->assertFalse($v->passes());
2583+
25682584
$v = new Validator($trans, ['foo' => '5'], ['foo' => 'Numeric|Min:3']);
25692585
$this->assertTrue($v->passes());
25702586

@@ -2597,6 +2613,18 @@ public function testValidateMax()
25972613
$v = new Validator($trans, ['foo' => '211'], ['foo' => 'Numeric|Max:100']);
25982614
$this->assertFalse($v->passes());
25992615

2616+
// an equal value qualifies.
2617+
$v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Max:3']);
2618+
$this->assertTrue($v->passes());
2619+
2620+
// '2.001' is considered as a float when the "Numeric" rule exists.
2621+
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Numeric|Max:3']);
2622+
$this->assertTrue($v->passes());
2623+
2624+
// '2.001' is a string of length 5 in absence of the "Numeric" rule.
2625+
$v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Max:3']);
2626+
$this->assertFalse($v->passes());
2627+
26002628
$v = new Validator($trans, ['foo' => '22'], ['foo' => 'Numeric|Max:33']);
26012629
$this->assertTrue($v->passes());
26022630

0 commit comments

Comments
 (0)