当前位置: 首页>>代码示例>>PHP>>正文


PHP ConstraintViolationList::add方法代码示例

本文整理汇总了PHP中Symfony\Component\Validator\ConstraintViolationList::add方法的典型用法代码示例。如果您正苦于以下问题:PHP ConstraintViolationList::add方法的具体用法?PHP ConstraintViolationList::add怎么用?PHP ConstraintViolationList::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Validator\ConstraintViolationList的用法示例。


在下文中一共展示了ConstraintViolationList::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExecuteMultipleMethods

 public function testExecuteMultipleMethods()
 {
     $object = new ExecuteValidatorTest_Object();
     $this->assertTrue($this->validator->isValid($object, new Execute(array('validateOne', 'validateTwo'))));
     $violations = new ConstraintViolationList();
     $violations->add(new ConstraintViolation('My message', array('parameter'), 'Root', 'foo.bar', 'invalidValue'));
     // context was reset
     $violations->add(new ConstraintViolation('Other message', array('other parameter'), 'Root', 'initial.property.path', 'otherInvalidValue'));
     $this->assertEquals($violations, $this->context->getViolations());
 }
开发者ID:rooster,项目名称:symfony,代码行数:10,代码来源:ExecuteValidatorTest.php

示例2: validate

 private function validate($month, array $months)
 {
     $errors = new ConstraintViolationList();
     if (count($months) == 0) {
         //TODO check if this is the first month which is terminated => there does not exist a purchase which is done in an earlier month
         $errors->add(new ConstraintViolation('accounting.previousMonthNotTerminated', 'accounting.previousMonthNotTerminated', ['%prev' => $month - 1, '%current' => $month], $month, 'month', null));
     } else {
         if (count($months) == 2 && !$months[0]->isReopened()) {
             $errors->add(new ConstraintViolation('accounting.givenMonthAlreadyTerminated', 'accounting.givenMonthAlreadyTerminated', ['%month' => $month], $month, 'month', null));
         }
     }
     return $errors;
 }
开发者ID:robstoll,项目名称:PuMa,代码行数:13,代码来源:AccountingController.php

示例3: testValidate_multipleGroups

 public function testValidate_multipleGroups()
 {
     $entity = new Entity();
     $metadata = new ClassMetadata(get_class($entity));
     $metadata->addPropertyConstraint('firstName', new FailingConstraint(array('groups' => 'First')));
     $metadata->addPropertyConstraint('lastName', new FailingConstraint(array('groups' => 'Second')));
     $this->factory->addClassMetadata($metadata);
     // The constraints of both groups failed
     $violations = new ConstraintViolationList();
     $violations->add(new ConstraintViolation('', array(), $entity, 'firstName', ''));
     $violations->add(new ConstraintViolation('', array(), $entity, 'lastName', ''));
     $result = $this->validator->validate($entity, array('First', 'Second'));
     $this->assertEquals($violations, $result);
 }
开发者ID:neokensou,项目名称:symfony,代码行数:14,代码来源:ValidatorTest.php

示例4: testCreateNewObject

 /**
  * Test creation of new object
  *
  * @return void
  */
 public function testCreateNewObject()
 {
     $objectContent = ['id' => 'one', 'second_id' => 'two'];
     $object = new EntityConverterEntity();
     $object->setIds($objectContent);
     $badProperties = new ConstraintViolationList();
     $badProperties->add(new ConstraintViolation('This is not a valid property of CLASS', 'This is not a valid property of CLASS', array(), null, null, null));
     $this->crudTransformer->expects($this->any())->method('arrayToObject')->willReturn($object);
     $this->crudTransformer->expects($this->any())->method('arrayToObjectPropertyValidation')->willReturn($badProperties);
     $referenceObject = new CircularReferenceEntity();
     $this->entityConverter->expects($this->any())->method('find')->willReturn($referenceObject);
     /** @var EntityConverterEntity $newObject */
     $newObject = $this->entityConverter->createOrUpdateNewObject('\\Ecentria\\Libraries\\EcentriaRestBundle\\Tests\\Entity\\EntityConverterEntity', new Request(array(), array(), array(), array(), array(), array(), json_encode($objectContent)), EntityConverter::MODE_CREATE, array('references' => array('class' => 'CircularReferenceEntity', 'name' => 'CircularReferenceEntity')), false);
     //test validation and references conversion
     $this->assertEquals($referenceObject, $newObject->getCircularReferenceEntity());
     $this->assertEquals($badProperties, $newObject->getViolations());
     $this->assertFalse($newObject->isValid());
     $secondIds = array('id' => 'test ONE', 'second_id' => 'test TWO');
     /** @var EntityConverterEntity $secondObject */
     $secondObject = $this->entityConverter->createOrUpdateNewObject('\\Ecentria\\Libraries\\EcentriaRestBundle\\Tests\\Entity\\EntityConverterEntity', new Request(array(), array(), $secondIds, array(), array(), array(), json_encode($objectContent)), EntityConverter::MODE_RETRIEVE, array(), false);
     //test set ids
     $this->assertEquals($secondIds, $secondObject->getIds());
     // Testing set Ids for update mode
     $secondObject = $this->entityConverter->createOrUpdateNewObject('\\Ecentria\\Libraries\\EcentriaRestBundle\\Tests\\Entity\\EntityConverterEntity', new Request(array(), array(), $secondIds, array(), array(), array(), json_encode($objectContent)), EntityConverter::MODE_UPDATE, array(), false);
     //test set ids
     $this->assertEquals($secondIds, $secondObject->getIds());
 }
开发者ID:RomanShumkov,项目名称:EcentriaRestBundle,代码行数:32,代码来源:EntityConverterTest.php

示例5: update

 /**
  * {@inheritdoc}
  *
  * Expected input format :
  * {
  *     'attribute': 'maximum_print_size',
  *     'code': '210_x_1219_mm',
  *     'sort_order': 2,
  *     'labels': {
  *         'de_DE': '210 x 1219 mm',
  *         'en_US': '210 x 1219 mm',
  *         'fr_FR': '210 x 1219 mm'
  *     }
  * }
  *
  * @throws BusinessValidationException
  */
 public function update($attributeOption, array $data, array $options = [])
 {
     if (!$attributeOption instanceof AttributeOptionInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\AttributeOptionInterface", "%s" provided.', ClassUtils::getClass($attributeOption)));
     }
     // TODO: ugly fix to workaround issue with "attribute.group.code: This value should not be blank."
     // in case of existing option, attribute is a proxy, attribute group too, the validated group code is null
     $attributeOption->getAttribute() !== null ? $attributeOption->getAttribute()->getGroup()->getCode() : null;
     $isNew = $attributeOption->getId() === null;
     $readOnlyFields = ['attribute', 'code'];
     $updateViolations = new ConstraintViolationList();
     foreach ($data as $field => $data) {
         $isReadOnlyField = in_array($field, $readOnlyFields);
         if ($isNew || !$isReadOnlyField) {
             try {
                 $this->setData($attributeOption, $field, $data);
             } catch (\InvalidArgumentException $e) {
                 $setViolation = new ConstraintViolation($e->getMessage(), $e->getMessage(), [], $attributeOption, null, null);
                 $updateViolations->add($setViolation);
             }
         }
     }
     $validatorViolations = $this->validator->validate($attributeOption);
     $updateViolations->addAll($validatorViolations);
     if ($updateViolations->count() > 0) {
         throw new BusinessValidationException($updateViolations);
     }
     return $this;
 }
开发者ID:vpetrovych,项目名称:pim-community-dev,代码行数:46,代码来源:AttributeOptionUpdater.php

示例6: testViolations

 public function testViolations()
 {
     $errorHandler = $this->getErrorHandler();
     $violations = new ConstraintViolationList();
     $violations->add($this->createViolation('test'));
     $errorHandler->violations($violations);
 }
开发者ID:ibrows,项目名称:datatrans,代码行数:7,代码来源:ErrorHandlerTest.php

示例7: testWalkConstraintBuildsAViolationIfFailed

 public function testWalkConstraintBuildsAViolationIfFailed()
 {
     $constraint = new ConstraintA();
     $this->walker->walkConstraint($constraint, 'foobar', 'Default', 'firstName.path');
     $violations = new ConstraintViolationList();
     $violations->add(new ConstraintViolation('message', array('param' => 'value'), 'Root', 'firstName.path', 'foobar'));
     $this->assertEquals($violations, $this->walker->getViolations());
 }
开发者ID:netixpro,项目名称:symfony,代码行数:8,代码来源:GraphWalkerTest.php

示例8: testValidateWithErrors

 public function testValidateWithErrors()
 {
     $violationList = new ConstraintViolationList();
     $violation1 = $this->getMockBuilder('Symfony\\Component\\Validator\\ConstraintViolation')->disableOriginalConstructor()->getMock();
     $violation1->expects($this->any())->method('getPropertyPath')->will($this->returnValue('from'));
     $violationList->add($violation1);
     $violation2 = $this->getMockBuilder('Symfony\\Component\\Validator\\ConstraintViolation')->disableOriginalConstructor()->getMock();
     $violation2->expects($this->any())->method('getPropertyPath')->will($this->returnValue('to'));
     $violationList->add($violation2);
     $violation3 = $this->getMockBuilder('Symfony\\Component\\Validator\\ConstraintViolation')->disableOriginalConstructor()->getMock();
     $violation3->expects($this->any())->method('getPropertyPath')->will($this->returnValue('cc'));
     $violationList->add($violation3);
     $this->context->expects($this->any())->method('getViolations')->will($this->returnValue($violationList));
     $this->context->expects($this->any())->method('addViolation')->with($this->constraint->message);
     $this->context->expects($this->any())->method('getPropertyPath')->will($this->returnValue('cc'));
     $this->getValidator()->validate(['test wrong email 1', 'test wrong email 2'], $this->constraint);
 }
开发者ID:Maksold,项目名称:platform,代码行数:17,代码来源:EmailAddressValidatorTest.php

示例9: testWalkConstraintBuildsAViolationIfFailed

 public function testWalkConstraintBuildsAViolationIfFailed()
 {
     $constraint = new ConstraintA();
     $this->interpolator->expects($this->once())->method('interpolate')->with($this->equalTo('message'), $this->equalTo(array('param' => 'value')))->will($this->returnValue('interpolated text'));
     $this->walker->walkConstraint($constraint, 'foobar', 'Default', 'firstName.path');
     $violations = new ConstraintViolationList();
     $violations->add(new ConstraintViolation('interpolated text', 'Root', 'firstName.path', 'foobar'));
     $this->assertEquals($violations, $this->walker->getViolations());
 }
开发者ID:vdumontier,项目名称:symfony,代码行数:9,代码来源:GraphWalkerTest.php

示例10: addViolation

 /**
  * {@inheritdoc}
  */
 public function addViolation($message, array $parameters = array(), $invalidValue = NULL, $plural = NULL, $code = NULL)
 {
     // The parameters $invalidValue and following are ignored by the new
     // API, as they are not present in the new interface anymore.
     // You should use buildViolation() instead.
     if (func_num_args() > 2) {
         throw new \LogicException('Legacy validator API is unsupported.');
     }
     $this->violations->add(new ConstraintViolation($this->translator->trans($message, $parameters, $this->translationDomain), $message, $parameters, $this->root, $this->propertyPath, $this->value, NULL, NULL, $this->constraint));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:ExecutionContext.php

示例11: addViolation

 /**
  * {@inheritdoc}
  */
 public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
 {
     // The parameters $invalidValue and following are ignored by the new
     // API, as they are not present in the new interface anymore.
     // You should use buildViolation() instead.
     if (func_num_args() > 2) {
         throw new BadMethodCallException('The parameters $invalidValue, $plural and $code are ' . 'not supported anymore as of Symfony 2.5. Please use ' . 'buildViolation() instead or enable the legacy mode.');
     }
     $this->violations->add(new ConstraintViolation($this->translator->trans($message, $parameters, $this->translationDomain), $message, $parameters, $this->root, $this->propertyPath, $this->value, null, null, $this->constraint));
 }
开发者ID:vadim2404,项目名称:symfony,代码行数:13,代码来源:ExecutionContext.php

示例12: testPluralization

 public function testPluralization()
 {
     $translator = new IdentityTranslator();
     $translator->setLocale('fr');
     $service = new I18nResponseFormatBuilder($translator);
     $violations = new ConstraintViolationList();
     $violations->add(new ConstraintViolation('Two apples', '{0}No apples|{1}One apple|]2,Inf]%count% apples', ['%count%' => 1], null, 'property', 'anything', 1));
     $result = $service->formatTranslatableViolationList($violations, false, true, ['en']);
     $this->assertSame('One apple', $result['en'][0]);
 }
开发者ID:sententiaregum,项目名称:sententiaregum,代码行数:10,代码来源:I18nResponseFormatBuilderTest.php

示例13: testProcessWithAllowedExtraFields

 public function testProcessWithAllowedExtraFields()
 {
     $this->filter->addOption('allowExtraFields', true);
     $data = ['title' => null, 'telephone' => '0155/555-555'];
     $this->filter->add('title', $constraint = new Constraints\NotNull());
     $list = new ConstraintViolationList();
     $list->add($this->buildConstraintViolation());
     $this->validator->expects($this->once())->method('validate')->willReturn($list);
     $this->assertFalse($this->filter->process($data));
     $this->assertEquals([1 => $list], $this->filter->getViolations());
 }
开发者ID:ddeboer,项目名称:data-import,代码行数:11,代码来源:ValidatorStepTest.php

示例14: addViolation

 /**
  * {@inheritdoc}
  */
 public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
 {
     // The parameters $invalidValue and following are ignored by the new
     // API, as they are not present in the new interface anymore.
     // You should use buildViolation() instead.
     if (func_num_args() > 2) {
         @trigger_error('The parameters $invalidValue, $plural and $code in method ' . __METHOD__ . ' are deprecated since version 2.5 and will be removed in 3.0. Use the ' . __CLASS__ . '::buildViolation method instead.', E_USER_DEPRECATED);
         $this->buildViolation($message, $parameters)->setInvalidValue($invalidValue)->setPlural($plural)->setCode($code)->addViolation();
         return;
     }
     $this->violations->add(new ConstraintViolation($this->translator->trans($message, $parameters, $this->translationDomain), $message, $parameters, $this->root, $this->propertyPath, $this->value, null, null, $this->constraint));
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:15,代码来源:ExecutionContext.php

示例15: addViolation

 /**
  * {@inheritdoc}
  */
 public function addViolation()
 {
     if (null === $this->plural) {
         $translatedMessage = $this->translator->trans($this->message, $this->parameters, $this->translationDomain);
     } else {
         try {
             $translatedMessage = $this->translator->transChoice($this->message, $this->plural, $this->parameters, $this->translationDomain);
         } catch (\InvalidArgumentException $e) {
             $translatedMessage = $this->translator->trans($this->message, $this->parameters, $this->translationDomain);
         }
     }
     $this->violations->add(new ConstraintViolation($translatedMessage, $this->message, $this->parameters, $this->root, $this->propertyPath, $this->invalidValue, $this->plural, $this->code, $this->constraint, $this->cause));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:16,代码来源:ConstraintViolationBuilder.php


注:本文中的Symfony\Component\Validator\ConstraintViolationList::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。