PositiveOrZero example

public function testConstraintsAreExecutedWithObject()
    {
        $number = new \stdClass();
        $number->type = 'positive';
        $number->value = 1;

        $this->setObject($number);
        $this->setPropertyPath('value');

        $constraints = [
            new PositiveOrZero(),
        ];

        $this->expectValidateValue(0, $number->value, $constraints);

        $this->validator->validate($number->value, new When([
            'expression' => 'this.type === "positive"',
            'constraints' => $constraints,
        ]));
    }

    public function testConstraintsAreExecutedWithValue()
    {
use Symfony\Component\Validator\Constraints\AbstractComparison;
use Symfony\Component\Validator\Constraints\PositiveOrZero;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;

/** * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> */
class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest
{
    protected static function createConstraint(array $options = null): Constraint
    {
        return new PositiveOrZero();
    }

    public static function provideValidComparisons(): array
    {
        return [
            [0, 0],
            [1, 0],
            [2, 0],
            [2.5, 0],
            ['0', '0'],
            ['333', '0'],
            [
Home | Imprint | This part of the site doesn't use cookies.