From b9d77bb08ae32c318f82e3dc2543773b78eee413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Thu, 7 Dec 2023 07:54:52 +0100 Subject: [PATCH] fix: Wrong type. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- tests/SP/Http/AddressTest.php | 52 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/SP/Http/AddressTest.php b/tests/SP/Http/AddressTest.php index d2ffe5b1..a40da46d 100644 --- a/tests/SP/Http/AddressTest.php +++ b/tests/SP/Http/AddressTest.php @@ -114,7 +114,7 @@ class AddressTest extends UnitaryTestCase * * @throws InvalidArgumentException */ - public function testBinary(string $address) + public function testToBinary(string $address) { $binary = Address::toBinary($address); @@ -125,7 +125,7 @@ class AddressTest extends UnitaryTestCase /** * @throws InvalidArgumentException */ - public function testBinaryInvalidIpv4() + public function testToBinaryInvalidIpv4() { $this->expectException(InvalidArgumentException::class); @@ -135,13 +135,48 @@ class AddressTest extends UnitaryTestCase /** * @throws InvalidArgumentException */ - public function testBinaryInvalidIpv6() + public function testToBinaryInvalidIpv6() { $this->expectException(InvalidArgumentException::class); Address::toBinary('1200::AB00:1234::2552:7777:1313'); } + /** + * @throws InvalidArgumentException + */ + public function testFromBinaryWithIpv4() + { + $address = self::$faker->ipv4; + + $out = Address::fromBinary(inet_pton($address)); + + $this->assertEquals($address, $out); + } + + /** + * @throws InvalidArgumentException + */ + public function testFromBinaryWithIpv6() + { + $address = self::$faker->ipv6; + + $out = Address::fromBinary(inet_pton($address)); + + $this->assertEquals($address, $out); + } + + /** + * @throws InvalidArgumentException + */ + public function testFromBinaryWithInvalidAddress() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid IP'); + + Address::fromBinary('something'); + } + /** * @dataProvider checkAddressProvider * @@ -172,6 +207,17 @@ class AddressTest extends UnitaryTestCase $this->assertEquals($expected, Address::check($address, $inAddress, Address::cidrToDec($inMask))); } + /** + * @throws InvalidArgumentException + */ + public function testCheckWithInvalidAddress() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid IP'); + + Address::check('123', '123', '123'); + } + /** * @throws InvalidArgumentException */