generated from yiisoft/package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt to last changes
yiisoft\validator
(#176)
* Add support of checking nested attributes, add more tests
- Loading branch information
1 parent
9843468
commit c7a7a96
Showing
7 changed files
with
113 additions
and
10 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
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Form\Tests\TestSupport\Form; | ||
|
||
use Yiisoft\Form\FormModel; | ||
use Yiisoft\Validator\Rule\Each; | ||
use Yiisoft\Validator\Rule\HasLength; | ||
use Yiisoft\Validator\RuleSet; | ||
|
||
final class EachForm extends FormModel | ||
{ | ||
private array $names = []; | ||
|
||
public function getRules(): array | ||
{ | ||
return ['names' => [Each::rule(new RuleSet([HasLength::rule()->max(10)]))]]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Form\Tests\Validator; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Form\Helper\HtmlFormErrors; | ||
use Yiisoft\Form\Tests\TestSupport\Form\EachForm; | ||
use Yiisoft\Form\Tests\TestSupport\TestTrait; | ||
|
||
final class EachValidatorTest extends TestCase | ||
{ | ||
use TestTrait; | ||
|
||
/** | ||
* @throws CircularReferenceException|InvalidConfigException|NotFoundException|NotInstantiableException | ||
*/ | ||
public function testEach(): void | ||
{ | ||
$eachForm = new EachForm(); | ||
$validator = $this->createValidatorMock(); | ||
|
||
$eachForm->setAttribute('names', ['wilmer', 'pedrovitelek', 'samdark']); | ||
$result = $validator->validate($eachForm); | ||
|
||
$this->assertSame( | ||
['names' => ['This value should contain at most {max, number} {max, plural, one{character} other{characters}}. pedrovitelek given.']], | ||
HtmlFormErrors::getAllErrors($eachForm), | ||
); | ||
} | ||
} |