public function testValidateWithTypeRegistered()
 {
     $value = 'foobar';
     $this->registry->expects($this->once())->method('has')->with($value)->willReturn(true);
     $this->context->expects($this->never())->method('buildViolation');
     $this->subject->validate($value, new JobType());
 }
 /**
  * @dataProvider provideInvalidExpressions
  * @param string $expression
  */
 public function testValidateWithInvalidExpression($expression)
 {
     $builder = $this->createMock(ConstraintViolationBuilderInterface::class);
     $this->context->expects($this->once())->method('buildViolation')->willReturn($builder);
     $builder->expects($this->once())->method('setParameter')->with('{{string}}', $expression)->willReturn($builder);
     $builder->expects($this->once())->method('addViolation');
     $this->subject->validate($expression, new CronExpression());
 }
 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']));
 }
 public function testValidateWithType()
 {
     $value = new \Abc\Bundle\SchedulerBundle\Model\Schedule();
     $value->setType('foobar');
     $value->setExpression('ScheduleExpression');
     $validator = $this->createMock(ValidatorInterface::class);
     $contextualValidator = $this->createMock(ContextualValidatorInterface::class);
     $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('atPath')->with('expression')->willReturn($contextualValidator);
     $contextualValidator->expects($this->once())->method('validate')->with('ScheduleExpression', new Expression(['type' => $value->getType()]));
     $this->subject->validate($value, new Schedule());
 }
 public function testValidateWithType()
 {
     $job = new Job();
     $job->setType('foobar');
     $job->setParameters(['JobParameters']);
     $validator = $this->createMock(ValidatorInterface::class);
     $contextualValidator = $this->createMock(ContextualValidatorInterface::class);
     $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('atPath')->with('parameters')->willReturn($contextualValidator);
     $contextualValidator->expects($this->once())->method('validate')->with(['JobParameters'], new Parameters(['type' => $job->getType()]));
     $this->subject->validate($job, new JobConstraint());
 }
 /**
  * @dataProvider provideValuesWithConstraints
  * @param array $parameters
  * @param array $constraints
  */
 public function testValidateWithValue(array $parameters, array $constraints)
 {
     $validator = $this->createMock(ValidatorInterface::class);
     $contextualValidator = $this->createMock(ContextualValidatorInterface::class);
     $provider = $this->createMock(ConstraintProviderInterface::class);
     $this->subject->register($provider);
     $this->registry->expects($this->once())->method('getTypeChoices')->willReturn(['foobar']);
     $provider->expects($this->any())->method('getConstraints')->with('foobar')->willReturn($constraints);
     $this->context->expects($this->once())->method('getValidator')->willReturn($validator);
     $validator->expects($this->once())->method('inContext')->with($this->context)->willReturn($contextualValidator);
     $contextualValidator->expects($this->exactly(count($constraints)))->method('atPath')->willReturn($contextualValidator);
     $contextualValidator->expects($this->exactly(count($constraints)))->method('validate');
     $this->subject->validate($parameters, new ParametersConstraint(['type' => 'foobar']));
 }
 /**
  * Test validate()
  *
  * @return void
  */
 public function testValidateAllowedNeeded()
 {
     $extref = ExtRef::create(__FILE__, __FUNCTION__);
     $constraint = new ExtReference();
     $constraint->collections = [__FILE__];
     $this->context->expects($this->never())->method('addViolation');
     $validator = $this->createValidator();
     $validator->validate($extref, $constraint);
 }
 /**
  * Testing circular reference
  *
  * @return void
  */
 public function testCircularReferenceFatalErrorOnGetParents()
 {
     $this->context->expects($this->once())->method('addViolationAt')->with('Parent', sprintf('You cannot set object #%s as parent for object #%s because of circular reference', 'test2', 'test1'));
     $channel1 = new CircularReferenceEntity();
     $channel1->setIds(array('id' => 'test1'));
     $channel2 = new CircularReferenceEntity();
     $channel2->setIds(array('id' => 'test2'));
     $channel3 = new CircularReferenceEntity();
     $channel3->setIds(array('id' => 'test3'));
     $constraint = new CircularReference();
     /*
      * Validation should go after each item
      * because we don't have batch update
      * operations for now
      */
     $channel2->setParent($channel1);
     $this->validator->validate($channel2, $constraint);
     $channel1->setParent($channel2);
     $this->validator->validate($channel1, $constraint);
     $channel3->setParent($channel2);
     $this->validator->validate($channel3, $constraint);
 }