私は配列を検証するために Validator Component を使用しています。
私の検証は条件付きなので、グループを作成します。
しかし、私はそれを正しく動作させることができません。バリデーターは、制約をチェックするときにグループを無視します。
これは私の(ユニット)テストです:
public function testValidator()
{
$book = array(
'title' => 'My Book',
'author' => array(
'first_name' => 'Fabien',
'last_name' => 'Potencier',
),
);
$constraint = new Assert\Collection(array(
'groups' => array('MyGroup'),
'fields' => array(
'title' => new Assert\Length(array('min' => 10, 'groups' => 'MyGroup')),
'author' => new Assert\Collection(array(
'groups' => array('MyGroup'),
'fields' => array(
'first_name' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 10))),
'last_name' => new Assert\Length(array('min' => 10, 'groups' => 'MyGroup')),
)
)),
)
));
// $this->v is the validator service
$errors = $this->v->validateValue($book, $constraint, null, array('MyGroup'));
$this->assertEquals(1, $errors->count(), $errors);
}
結果は次のとおりです。
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from phpunit.xml
.F
Time: 0 seconds, Memory: 3.00Mb
There was 1 failure:
1) WebFactory\ValidationNormalizer\Tests\ValidationNormalizerTest::testValidator
[title]:
This value is too short. It should have 10 characters or more.
[author][first_name]:
This value is too short. It should have 10 characters or more.
[author][last_name]:
This value is too short. It should have 10 characters or more.
Failed asserting that 3 matches expected 1.
src/WebFactory/ValidationNormalizer/Tests/ValidationNormalizerTest.php:64
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
MyGroup 制約のみを検証したい。
エラーはどこにありますか?