Cidr example

use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints\Cidr;
use Symfony\Component\Validator\Constraints\Ip;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;

class CidrTest extends TestCase
{
    public function testForAll()
    {
        $cidrConstraint = new Cidr();

        self::assertEquals(Ip::ALL, $cidrConstraint->version);
        self::assertEquals(0, $cidrConstraint->netmaskMin);
        self::assertEquals(128, $cidrConstraint->netmaskMax);
    }

    public function testForV4()
    {
        $cidrConstraint = new Cidr(['version' => Ip::V4]);

        self::assertEquals(Ip::V4, $cidrConstraint->version);
        
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

class CidrValidatorTest extends ConstraintValidatorTestCase
{
    protected function createValidator(): CidrValidator
    {
        return new CidrValidator();
    }

    public function testNullIsValid()
    {
        $this->validator->validate(null, new Cidr());

        $this->assertNoViolation();
    }

    public function testEmptyStringIsValid()
    {
        $this->validator->validate('', new Cidr());

        $this->assertNoViolation();
    }

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