expectException(UnexpectedTypeException::class); $this->validator->validate('foo', new NotBlank()); } /** * @dataProvider getValidData * @param string $input */ public function testConstraintWithValidData($input) { $constraint = new Duration(); $this->validator->validate($input, $constraint); $this->assertNoViolation(); } public function getInvalidData() { return [ ['13-13'], ['13.13'], ['3127::00'], ['3127:00:'], [':3127:00'], ['::3127'], ['foo'], ]; } /** * @dataProvider getInvalidData * @param mixed $input */ public function testValidationError($input) { $constraint = new Duration([ 'message' => 'myMessage', ]); $this->validator->validate($input, $constraint); $expectedFormat = \is_string($input) ? '"' . $input . '"' : $input; $this->buildViolation('myMessage') ->setParameter('{{ value }}', $expectedFormat) ->setCode(Regex::REGEX_FAILED_ERROR) ->assertRaised(); } }