diff --git a/src/Model/Fields/Payer/IP.php b/src/Model/Fields/Payer/IP.php index eab1e0f..f1409bb 100644 --- a/src/Model/Fields/Payer/IP.php +++ b/src/Model/Fields/Payer/IP.php @@ -12,13 +12,12 @@ class IP extends Field { protected $name = __CLASS__; protected $type = self::STRING; - protected $minLength = 3; protected $maxLength = 255; protected function initValidators() { $this->addValidator(function ($value) { - if (false === filter_var($value, FILTER_VALIDATE_IP)) { + if (!empty($value) && false === filter_var($value, FILTER_VALIDATE_IP)) { return new FieldValidationResult(false, 'Invalid IP address.'); } diff --git a/tests/Model/Fields/Payer/IpTest.php b/tests/Model/Fields/Payer/IpTest.php index e36f3db..b938a6c 100644 --- a/tests/Model/Fields/Payer/IpTest.php +++ b/tests/Model/Fields/Payer/IpTest.php @@ -13,7 +13,7 @@ public function testIpv4() $ip = new Ip(); $ip->setValue('127.0.0.1'); - $this->assertEquals('127.0.0.1', $ip->getValue()); + $this->assertSame('127.0.0.1', $ip->getValue()); } public function testIpv6() @@ -21,28 +21,33 @@ public function testIpv6() $ip = new Ip(); $ip->setValue('2001:db8::1'); - $this->assertEquals('2001:db8::1', $ip->getValue()); + $this->assertSame('2001:db8::1', $ip->getValue()); } - public function testInvalidIp() + public function testEmptyString() { $ip = new Ip(); + $ip->setValue(''); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Validation failed for field Tpay\OpenApi\Model\Fields\Payer\IP: Invalid IP address.'); - - $ip->setValue('TEST123'); + $this->assertSame('', $ip->getValue()); } public function testNull() + { + $ip = new Ip(); + $ip->setValue(null); + + $this->assertSame(null, $ip->getValue()); + } + + public function testInvalidIp() { $ip = new Ip(); $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Value of field Tpay\OpenApi\Model\Fields\Payer\IP is too short. Min required 3'); $this->expectExceptionMessage('Validation failed for field Tpay\OpenApi\Model\Fields\Payer\IP: Invalid IP address.'); - $ip->setValue(null); + $ip->setValue('TEST123'); } public function testWrongType()