Skip to content

Commit 70fbd48

Browse files
committed
update
1 parent aef3e91 commit 70fbd48

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

src/Validator/MaxLength.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function message(string $message): self
2323

2424
public function evaluate(string $value): bool
2525
{
26-
return mb_strlen($value) <= $this->maxLength;
26+
return mb_strlen(trim($value)) <= $this->maxLength;
2727
}
2828

2929
public function validate(string $value): string

src/Validator/MinLength.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function message(string $message): self
2323

2424
public function evaluate(string $value): bool
2525
{
26-
return mb_strlen($value) >= $this->minLength;
26+
return mb_strlen(trim($value)) >= $this->minLength;
2727
}
2828

2929
public function validate(string $value): string
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace MintyPHP\Tests\Validators;
4+
5+
use MintyPHP\Form\Validator\Validators;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class MaxLengthValidatorTest extends TestCase
10+
{
11+
public static function maxLengthDataProvider(): array
12+
{
13+
return [
14+
['', 0, true],
15+
['', 1, true],
16+
['😜', 0, false],
17+
['😜', 1, true],
18+
['😜', 2, true],
19+
['12', 1, false],
20+
['12', 2, true],
21+
['12', 3, true],
22+
['123 78', 7, false],
23+
['123 78', 8, true],
24+
['123 78', 9, true],
25+
['12345 ', 4, false],
26+
['12345 ', 5, true],
27+
['12345 ', 6, true],
28+
['12345 ', 7, true],
29+
[' 45678', 4, false],
30+
[' 45678', 5, true],
31+
[' 45678', 6, true],
32+
[' 45678', 7, true],
33+
];
34+
}
35+
36+
#[DataProvider('maxLengthDataProvider')]
37+
public function testValidExpression(string $input, int $length, bool $expected): void
38+
{
39+
$validator = Validators::maxLength($length, 'invalid length');
40+
$this->assertEquals($validator->validate($input) === '', $expected);
41+
}
42+
}

tests/Validators/MinLengthValidatorTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ public static function minLengthDataProvider(): array
1313
return [
1414
['', 0, true],
1515
['', 1, false],
16-
['1', 0, true],
17-
['1', 1, true],
18-
['1', 2, false],
16+
['😜', 0, true],
17+
['😜', 1, true],
18+
['😜', 2, false],
1919
['12', 1, true],
2020
['12', 2, true],
2121
['12', 3, false],
2222
['123 78', 7, true],
2323
['123 78', 8, true],
2424
['123 78', 9, false],
25-
['12345 ', 7, true],
26-
['12345 ', 8, true],
27-
['12345 ', 9, false],
28-
[' 45678', 7, true],
29-
[' 45678', 8, true],
30-
[' 45678', 9, false],
25+
['12345 ', 4, true],
26+
['12345 ', 5, true],
27+
['12345 ', 6, false],
28+
['12345 ', 7, false],
29+
[' 45678', 4, true],
30+
[' 45678', 5, true],
31+
[' 45678', 6, false],
32+
[' 45678', 7, false],
3133
];
3234
}
3335

0 commit comments

Comments
 (0)