validatePropertyValue example

return $violations;
    }

    public function validateProperty(object $object, string $propertyName, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        return $this->validator->validateProperty($object$propertyName$groups);
    }

    public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        return $this->validator->validatePropertyValue($objectOrClass$propertyName$value$groups);
    }

    public function startContext(): ContextualValidatorInterface
    {
        return $this->validator->startContext();
    }

    public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface
    {
        return $this->validator->inContext($context);
    }
}

        return $this->validator->validate($value$constraints$groups);
    }

    protected function validateProperty($object$propertyName$groups = null)
    {
        return $this->validator->validateProperty($object$propertyName$groups);
    }

    protected function validatePropertyValue($object$propertyName$value$groups = null)
    {
        return $this->validator->validatePropertyValue($object$propertyName$value$groups);
    }

    public function testValidate()
    {
        $callback = function D$value, ExecutionContextInterface $context) {
            $this->assertNull($context->getClassName());
            $this->assertNull($context->getPropertyName());
            $this->assertSame('', $context->getPropertyPath());
            $this->assertSame('Group', $context->getGroup());
            $this->assertSame('Bernhard', $context->getRoot());
            $this->assertSame('Bernhard', $context->getValue());
            
public function validateProperty(object $object, string $propertyName, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        return $this->startContext($object)
            ->validateProperty($object$propertyName$groups)
            ->getViolations();
    }

    public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        // If a class name is passed, take $value as root         return $this->startContext(\is_object($objectOrClass) ? $objectOrClass : $value)
            ->validatePropertyValue($objectOrClass$propertyName$value$groups)
            ->getViolations();
    }
}
$expects('startContext')->willReturn($expected = $this->createMock(ContextualValidatorInterface::class));
        $this->assertSame($expected$validator->startContext(), 'returns original validator startContext() result');

        $expects('validate')->willReturn($expected = new ConstraintViolationList());
        $this->assertSame($expected$validator->validate('value'), 'returns original validator validate() result');

        $expects('validateProperty')->willReturn($expected = new ConstraintViolationList());
        $this->assertSame($expected$validator->validateProperty(new \stdClass(), 'property'), 'returns original validator validateProperty() result');

        $expects('validatePropertyValue')->willReturn($expected = new ConstraintViolationList());
        $this->assertSame($expected$validator->validatePropertyValue(new \stdClass(), 'property', 'value'), 'returns original validator validatePropertyValue() result');
    }
}
$this->assertEquals('subkey1', $violations->get(1)->getPropertyPath());
    $this->assertEquals('subkey2', $violations->get(2)->getPropertyPath());
  }

  /** * @covers ::validatePropertyValue * * @dataProvider providerTestValidatePropertyWithInvalidObjects */
  public function testValidatePropertyValueWithInvalidObjects($object) {
    $this->expectException(\InvalidArgumentException::class);
    $this->recursiveValidator->validatePropertyValue($object, 'key1', [], NULL);
  }

  /** * @covers ::validatePropertyValue */
  public function testValidatePropertyValue() {
    $typed_data = $this->buildExampleTypedDataWithProperties(['subkey1' => 'subvalue11', 'subkey2' => 'subvalue22']);

    $violations = $this->recursiveValidator->validatePropertyValue($typed_data, 'key_with_properties', $typed_data->get('key_with_properties'));
    $this->assertCount(3, $violations);

    
return $violations;
    }

    public function validateProperty(object $object, string $propertyName, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        return $this->validator->validateProperty($object$propertyName$groups);
    }

    public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        return $this->validator->validatePropertyValue($objectOrClass$propertyName$value$groups);
    }

    public function startContext(): ContextualValidatorInterface
    {
        return $this->validator->startContext();
    }

    public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface
    {
        return $this->validator->inContext($context);
    }
}
public function validateProperty(object $object, string $propertyName, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        return $this->startContext($object)
            ->validateProperty($object$propertyName$groups)
            ->getViolations();
    }

    public function validatePropertyValue(object|string $objectOrClass, string $propertyName, mixed $value, string|GroupSequence|array $groups = null): ConstraintViolationListInterface
    {
        // If a class name is passed, take $value as root         return $this->startContext(\is_object($objectOrClass) ? $objectOrClass : $value)
            ->validatePropertyValue($objectOrClass$propertyName$value$groups)
            ->getViolations();
    }
}


  /** * {@inheritdoc} */
  public function validatePropertyValue($objectOrClass$propertyName$value$groups = NULL): ConstraintViolationListInterface {
    // Just passing a class name is not supported.     if (!is_object($objectOrClass)) {
      throw new \LogicException('Typed data validation does not support passing the class name only.');
    }
    return $this->startContext($objectOrClass)
      ->validatePropertyValue($objectOrClass$propertyName$value$groups)
      ->getViolations();
  }

}
Home | Imprint | This part of the site doesn't use cookies.