createConstraint example


    }

    /** * @dataProvider throwsOnNonNumericValuesProvider */
    public function testThrowsOnNonNumericValues(string $expectedGivenType$value$comparedValue)
    {
        $this->expectException(UnexpectedValueException::class);
        $this->expectExceptionMessage(sprintf('Expected argument of type "numeric", "%s" given', $expectedGivenType));

        $this->validator->validate($value$this->createConstraint([
            'value' => $comparedValue,
        ]));
    }

    public static function throwsOnNonNumericValuesProvider()
    {
        return [
            [\stdClass::class, 2, new \stdClass()],
            [\ArrayIterator::classnew \ArrayIterator(), 12],
        ];
    }

    

        ];
    }

    /** * @dataProvider provideInvalidConstraintOptions */
    public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
    {
        $this->expectException(ConstraintDefinitionException::class);
        $this->expectExceptionMessage('requires either the "value" or "propertyPath" option to be set.');
        $this->createConstraint($options);
    }

    public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
    {
        $this->expectException(ConstraintDefinitionException::class);
        $this->expectExceptionMessage('requires only one of the "value" or "propertyPath" options to be set, not both.');
        $this->createConstraint([
            'value' => 'value',
            'propertyPath' => 'propertyPath',
        ]);
    }

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