expectException(UnexpectedTypeException::class); $this->validator->validate('foo', new NotBlank()); } /** * @dataProvider getValidData * @param string $input */ public function testConstraintWithValidData($input) { $constraint = new DateTimeFormat(); $this->validator->validate($input, $constraint); $this->assertNoViolation(); } public function getInvalidData() { return [ ['13-13'], ['3127::00'], ['3127:00:'], [':3127:00'], ['::3127'], ]; } /** * @dataProvider getInvalidData * @param mixed $input */ public function testValidationError($input) { $constraint = new DateTimeFormat(); $this->validator->validate($input, $constraint); $expectedFormat = \is_string($input) ? '"' . $input . '"' : $input; $this->buildViolation('The given value is not a valid datetime format.') ->setCode(DateTimeFormat::INVALID_FORMAT) ->assertRaised(); } }