public function testValidate()
 {
     $this->repository->expects($this->once())->method('findDuplicate')->with($this->lineItem)->will($this->returnValue(true));
     $this->registry->expects($this->once())->method('getRepository')->with(self::LINE_ITEM_SHORTCUT)->will($this->returnValue($this->repository));
     $this->context->expects($this->once())->method('addViolation')->with($this->constraint->message);
     $validator = new LineItemValidator($this->registry);
     $validator->initialize($this->context);
     $validator->validate($this->lineItem, $this->constraint);
 }
Esempio n. 2
0
 /**
  * @dataProvider validateDataProvider
  * @param mixed $data
  * @param boolean $correct
  */
 public function testValidate($data, $correct)
 {
     if (!$correct) {
         $this->context->expects($this->once())->method('addViolation')->with($this->constraint->message);
     } else {
         $this->context->expects($this->never())->method('addViolation');
     }
     $this->validator->validate($data, $this->constraint);
 }
 /**
  * @param mixed $data
  * @param bool  $expected
  *
  * @dataProvider validateDataProvider
  */
 public function testValidate($data, $expected)
 {
     $constraint = new ExtensionLoaded();
     $this->context = $this->getMock('Symfony\\Component\\Validator\\ExecutionContextInterface');
     if ($expected) {
         $this->validator->initialize($this->context);
         $this->context->expects($this->once())->method('addViolation')->with($this->isType('string'));
     }
     $this->validator->validate($data, $constraint);
 }
 public function testValidateNotExistingProduct()
 {
     $price = $this->getProductPrice();
     // Set null to product and productSku
     $class = new \ReflectionClass($price);
     $product = $class->getProperty('product');
     $product->setAccessible(true);
     $product->setValue($price, null);
     $productSku = $class->getProperty('productSku');
     $productSku->setAccessible(true);
     $productSku->setValue($price, null);
     $this->context->expects($this->once())->method('addViolationAt')->with('product', $this->constraint->notExistingProductMessage);
     $this->validator->validate($price, $this->constraint);
 }
 public function testNoViolationsOnUniqueUserProperty()
 {
     $this->ldapManagerMock->expects($this->once())->method('findUserByUsername')->will($this->returnValue(null))->with($this->equalTo($this->user->getUsername()));
     $this->validatorContext->expects($this->never())->method('addViolation');
     $this->validator->validate($this->user, $this->constraint);
 }
 protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group)
 {
     $this->context->expects($this->at($i))->method('validateValue')->with($value, $constraints, $propertyPath, $group);
 }
 /**
  * @param mixed $data
  * @param boolean $valid
  * @dataProvider validateProvider
  */
 public function testValidate($data, $valid)
 {
     $this->context->expects($valid ? $this->never() : $this->once())->method('addViolationAt')->with('productUnit', $this->constraint->message);
     $this->validator->validate($data, $this->constraint);
 }
 public function testWithoutPrice()
 {
     $productPrice = new ProductPrice();
     $this->context->expects($this->never())->method('addViolationAt');
     $this->validator->validate($productPrice, $this->constraint);
 }
 public function testValidateWithDuplications()
 {
     $this->context->expects($this->once())->method('addViolation')->with($this->constraint->message);
     $data = new ArrayCollection([$this->createPriceList(1, 10, 'kg', 'USD'), $this->createPriceList(1, 10, 'kg', 'USD')]);
     $this->validator->validate($data, $this->constraint);
 }
Esempio n. 10
0
 /**
  * @param $options
  * @param $value
  * @param $violation
  *
  * @dataProvider validateDataProvider
  */
 public function testValidate($options, $value, $violation)
 {
     $this->context->expects($violation ? $this->once() : $this->never())->method('addViolation');
     $constraint = new Decimal($options);
     $this->validator->validate($value, $constraint);
 }
 /**
  * @param boolean $isValid
  * @param mixed $inputData
  * @dataProvider validateProvider
  */
 public function testValidate($isValid, $inputData)
 {
     $this->context->expects($isValid ? $this->never() : $this->once())->method('addViolationAt')->with('currency', $this->constraint->message);
     $this->validator->validate($inputData, $this->constraint);
 }