public function testValidateWithTypeRegistered() { $validator = $this->createMock(ValidatorInterface::class); $contextualValidator = $this->createMock(ContextualValidatorInterface::class); $constraint = $this->createMock(Constraint::class); $this->registry->expects($this->once())->method('has')->with('ScheduleType')->willReturn(true); $this->registry->expects($this->once())->method('get')->with('ScheduleType')->willReturn($constraint); $this->context->expects($this->once())->method('getValidator')->willReturn($validator); $validator->expects($this->once())->method('inContext')->with($this->context)->willReturn($contextualValidator); $contextualValidator->expects($this->once())->method('validate')->with('foobar', $constraint); $this->subject->validate('foobar', new Expression(['type' => 'ScheduleType'])); }
/** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (null === $value) { return; } if (!$constraint->type) { throw new ConstraintDefinitionException('"type" must be specified on constraint Expression'); } if (!$this->registry->has($constraint->type)) { return; } $this->context->getValidator()->inContext($this->context)->validate($value, $this->registry->get($constraint->type)); }
/** * @expectedException \InvalidArgumentException */ public function testGetThrowsInvalidArgumentException() { $this->subject->get('foo'); }