public function setUp()
 {
     parent::setUp();
     $this->validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
     $this->validator->expects($this->never())->method('validate')->will($this->returnValue(array()));
     $this->listener = new ValidationListener($this->validator);
 }
예제 #2
0
 /**
  * @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @expectedMessage expected exception.
  */
 public function testValidationErrorsInStrictMode()
 {
     $param = $this->createMockedParam('foo', null, [], false, null, ['constraint']);
     list($fetcher, $method) = $this->getFetcherToCheckValidation($param);
     $errors = $this->getMock('Symfony\\Component\\Validator\\ConstraintViolationListInterface');
     $errors->expects($this->once())->method('count')->willReturn(1);
     $this->validator->expects($this->once())->method('validate')->with('value', array('constraint'))->willReturn($errors);
     $this->violationFormatter->expects($this->once())->method('formatList')->with($param, $errors)->willReturn('expected exception.');
     $method->invokeArgs($fetcher, array($param, 'value', true));
 }
예제 #3
0
 public function testProcessInvalidSegment()
 {
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->assertProcessSegment();
     $this->form->expects($this->once())->method('isValid')->will($this->returnValue(false));
     $violation = $this->getMockForAbstractClass('Symfony\\Component\\Validator\\ConstraintViolationInterface');
     $violation->expects($this->once())->method('getMessage')->will($this->returnValue('message'));
     $violation->expects($this->once())->method('getMessageTemplate')->will($this->returnValue('message template'));
     $violation->expects($this->once())->method('getMessageParameters')->will($this->returnValue(['test']));
     $violation->expects($this->once())->method('getMessagePluralization')->will($this->returnValue('message pluralization'));
     $errors = new ConstraintViolationList([$violation]);
     $this->validator->expects($this->once())->method('validate')->with($this->isInstanceOf('Oro\\Bundle\\SegmentBundle\\Entity\\Segment'), ['Default', 'marketing_list'])->will($this->returnValue($errors));
     $this->translator->expects($this->once())->method('trans')->with($this->isType('string'), $this->isType('array'))->will($this->returnValue('Marketing List test segment'));
     $this->form->expects($this->once())->method('addError')->with(new FormError('message', 'message template', ['test'], 'message pluralization'));
     $this->manager->expects($this->never())->method('persist');
     $this->manager->expects($this->never())->method('flush');
     $this->assertFalse($this->handler->process($this->testEntity));
     $this->assertSegmentData();
 }