Skip to content

Commit 8b0c521

Browse files
committed
update
1 parent bd53f9a commit 8b0c521

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 EmailValidatorTest extends TestCase
10+
{
11+
public static function addressDataProvider(): array
12+
{
13+
return [
14+
['[email protected]', true],
15+
['[email protected]', true],
16+
['', false],
17+
['103mail.com', false],
18+
['asd@[email protected]', false],
19+
];
20+
}
21+
22+
#[DataProvider('addressDataProvider')]
23+
public function testValidEmail(string $address, bool $expected): void
24+
{
25+
$validator = Validators::email('invalid email');
26+
$this->assertEquals($validator->validate($address) === '', $expected);
27+
}
28+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 ExpressionValidatorTest extends TestCase
10+
{
11+
public static function expressionDataProvider(): array
12+
{
13+
return [
14+
['10', '>', '9', true],
15+
['10', '>=', '10', true],
16+
['10', '<', '11', true],
17+
['10', '<=', '10', true],
18+
['10.5', '>', '9.5', true],
19+
['10.5', '<=', '10.5', true],
20+
['10.5', '>=', '10.5', true],
21+
['10.5', '<', '10.5', false],
22+
['10.5', '>', '10.5', false],
23+
['10.5', '<=', '9.5', false],
24+
['10.5', '>=', '11.5', false],
25+
['10.5', '<', '11.5', true],
26+
['10.5', '>=', '9.5', true],
27+
['10.5', '<=', '9.99999', false],
28+
['9.99999', '<=', '11.0', true],
29+
];
30+
}
31+
32+
#[DataProvider('expressionDataProvider')]
33+
public function testValidExpression(string $input, string $comperator, string $value, bool $expected): void
34+
{
35+
$validator = Validators::expression($comperator, $value, 'invalid value');
36+
$this->assertEquals($validator->validate($input) === '', $expected);
37+
}
38+
}

0 commit comments

Comments
 (0)