Skip to content

Commit ac5725c

Browse files
committed
update
1 parent 2e61345 commit ac5725c

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// create a form object
1414
$form = E::form([
15-
E::field(E::text('username')->required(), E::label('Username')),
15+
E::field(E::text('username')->required(), E::label('Username'), [V::minLength(1)]),
1616
E::field(E::password('password'), E::label('Password')),
1717
E::field(E::submit('Login')),
1818
]);

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($value) >= $this->minLength;
2727
}
2828

2929
public function validate(string $value): string

tests/Validators/EmailValidatorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public static function addressDataProvider(): array
1919
];
2020
}
2121

22-
#[DataProvider('addressDataProvider')]
22+
/**
23+
* @dataProvider addressDataProvider
24+
*/
2325
public function testValidEmail(string $address, bool $expected): void
2426
{
2527
$validator = Validators::email('invalid email');
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 MinLengthValidatorTest extends TestCase
10+
{
11+
public static function minLengthDataProvider(): array
12+
{
13+
return [
14+
['', 0, true],
15+
['', 1, false],
16+
['1', 0, true],
17+
['1', 1, true],
18+
['1', 2, false],
19+
['12', 1, true],
20+
['12', 2, true],
21+
['12', 3, false],
22+
['123 78', 7, true],
23+
['123 78', 8, true],
24+
['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],
31+
];
32+
}
33+
34+
#[DataProvider('minLengthDataProvider')]
35+
public function testValidExpression(string $input, int $length, bool $expected): void
36+
{
37+
$validator = Validators::minLength($length, 'invalid length');
38+
$this->assertEquals($validator->validate($input) === '', $expected);
39+
}
40+
}

0 commit comments

Comments
 (0)