-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Validation example, more tests, fix code style
- Loading branch information
Showing
3 changed files
with
28 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,8 @@ public function testFunction(): void | |
{ | ||
$source = [ | ||
'id' => 10, | ||
'email' => '[email protected]', | ||
'phone' => '+1-111-111-1111', | ||
'email' => 'some@@email.com', | ||
'phone' => '000+1-111-111-1111', | ||
'ip' => '127.0.0.256' | ||
]; | ||
|
||
|
@@ -26,11 +26,13 @@ public function testFunction(): void | |
$source, | ||
a::toKey('email', a::pipe( | ||
a::get('[email]'), | ||
a::validate(v::email()), | ||
a::validate(v::email()->setName('E-mail')), | ||
a::ifValidationFailed(a::value('[email protected]')), | ||
)), | ||
a::toKey('phone', a::pipe( | ||
a::get('[phone]'), | ||
a::validate(v::phone()), | ||
a::validate(v::phone()->setName('Phone')), | ||
a::ifValidationFailed(a::ignore()) | ||
)), | ||
a::toKey('ip', a::pipe( | ||
a::get('[ip]'), | ||
|
@@ -41,19 +43,28 @@ public function testFunction(): void | |
|
||
self::assertSame( | ||
[ | ||
'email' => '[email protected]', | ||
'phone' => '+1-111-111-1111', | ||
'email' => '[email protected]', | ||
'ip' => '127.0.0.1', | ||
], | ||
$result | ||
); | ||
|
||
$validationContext = $context->get(ValidationContextInterface::class); | ||
|
||
self::assertTrue($context->has(ValidationContextInterface::class)); | ||
self::assertTrue($context->get(ValidationContextInterface::class)->hasErrors()); | ||
self::assertCount(1, $context->get(ValidationContextInterface::class)->getErrors()); | ||
self::assertTrue($validationContext->hasErrors()); | ||
self::assertCount(3, $validationContext->getErrors()); | ||
self::assertSame( | ||
['IP Address' => 'IP Address must be an IP address'], | ||
$context->get(ValidationContextInterface::class)->getErrors()[0]->getMessages() | ||
[ | ||
'E-mail' => 'E-mail must be valid email', | ||
'Phone' => 'Phone must be a valid telephone number', | ||
'IP Address' => 'IP Address must be an IP address', | ||
], | ||
[ | ||
...$validationContext->getErrors()[0]->getMessages(), | ||
...$validationContext->getErrors()[1]->getMessages(), | ||
...$validationContext->getErrors()[2]->getMessages(), | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters