public function testInitializeObjectsOnFirstValidation()
 {
     $test = $this;
     $entity = new Entity();
     $entity->initialized = false;
     // prepare initializers that set "initialized" to true
     $initializer1 = $this->getMock('Symfony\\Component\\Validator\\ObjectInitializerInterface');
     $initializer2 = $this->getMock('Symfony\\Component\\Validator\\ObjectInitializerInterface');
     $initializer1->expects($this->once())->method('initialize')->with($entity)->will($this->returnCallback(function ($object) {
         $object->initialized = true;
     }));
     $initializer2->expects($this->once())->method('initialize')->with($entity);
     $this->visitor = new ValidationVisitor('Root', $this->metadataFactory, new ConstraintValidatorFactory(), new DefaultTranslator(), null, array($initializer1, $initializer2));
     // prepare constraint which
     // * checks that "initialized" is set to true
     // * validates the object again
     $callback = function ($object, ExecutionContextInterface $context) use($test) {
         $test->assertTrue($object->initialized);
         // validate again in same group
         $context->validate($object);
         // validate again in other group
         $context->validate($object, '', 'SomeGroup');
     };
     $this->metadata->addConstraint(new Callback(array($callback)));
     $this->visitor->validate($entity, 'Default', '');
     $this->assertTrue($entity->initialized);
 }
 /**
  * @expectedException \Symfony\Component\Validator\Exception\NoSuchMetadataException
  */
 public function testValidateCascadedPropertyRequiresObjectOrArray()
 {
     $entity = new Entity();
     $entity->reference = 'no object';
     $this->metadata->addPropertyConstraint('reference', new Valid());
     $this->visitor->validate($entity, 'Default', '');
 }
 public function testWalkObjectOnceInVisitorAndOnceInWalkerValidatesConstraintsOnce()
 {
     $this->metadata->addConstraint(new ConstraintA());
     $entity = new Entity();
     $this->visitor->validate($entity, 'Default', '');
     $this->walker->walkObject($this->metadata, $entity, 'Default', '');
     $this->assertCount(1, $this->walker->getViolations());
 }
 /**
  * Validates an object or an array.
  *
  * @param      $value
  * @param      $group
  * @param      $propertyPath
  * @param      $traverse
  * @param bool $deep
  *
  * @deprecated Deprecated since version 2.2, to be removed in 2.3.
  */
 public function walkReference($value, $group, $propertyPath, $traverse, $deep = false)
 {
     trigger_error('walkReference() is deprecated since version 2.2 and will be removed in 2.3.', E_USER_DEPRECATED);
     $this->visitor->validate($value, $group, $propertyPath, $traverse, $deep);
 }
Example #5
0
 /**
  * Validates an object or an array.
  *
  * @param      $value
  * @param      $group
  * @param      $propertyPath
  * @param      $traverse
  * @param bool $deep
  *
  * @deprecated Deprecated since version 2.2, to be removed in 2.3.
  */
 public function walkReference($value, $group, $propertyPath, $traverse, $deep = false)
 {
     $this->visitor->validate($value, $group, $propertyPath, $traverse, $deep);
 }