enableAnnotationMapping()->getValidator(); $validations = $validator->validate($value); if (!is_array($fieldNames)) { $fieldNames = [$fieldNames]; } $violatedFields = []; /** @var ConstraintViolationInterface $validation */ foreach ($validations as $validation) { $violatedFields[] = $validation->getPropertyPath(); } foreach ($fieldNames as $id => $propertyPath) { $foundField = false; if (in_array($propertyPath, $violatedFields)) { $foundField = true; unset($violatedFields[$id]); } $this->assertTrue($foundField, 'Failed finding violation for field: ' . $propertyPath); } $this->assertEmpty($violatedFields, sprintf('Unexpected violations found: %s', implode(', ', $violatedFields))); $expected = count($fieldNames); $actual = $validations->count(); $this->assertEquals($expected, $actual, sprintf('Expected %s violations, found %s.', $expected, $actual)); } }