Skip to content

Commit

Permalink
#23557 fix(*): fix unit tests once more
Browse files Browse the repository at this point in the history
  • Loading branch information
micharoesler committed Feb 3, 2025
1 parent 9323676 commit af21061
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function parse(string $ip): self
}

if (is_numeric($ip)) {
return self::parseLong($ip);
return self::parseLong((int) $ip);
}

return new self($ip);
Expand Down Expand Up @@ -197,7 +197,7 @@ public function toLong(): string
$octet = self::IP_V6_OCTETS - 1;
foreach (unpack('C*', $this->in_addr) as $char) {
$exponent = (string) $octet--;
$long = bcadd($long, bcmul((string) $char, bcpow('256', $exponent)));
$long = bcadd((string) $long, bcmul((string) $char, bcpow('256', $exponent)));
}
}

Expand Down Expand Up @@ -255,4 +255,4 @@ public function prev(int $to = 1): self

return new self(inet_ntop(pack(...array_merge(['C*'], $unpacked))));
}
}
}
4 changes: 2 additions & 2 deletions src/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getNetworks(): array
$excluded = $span->exclude($this->lastIP->next()->__toString());
} else {
$excluded = array_pop($networks);
$excluded = $excluded->exclude($this->lastIP->next());
$excluded = $excluded->exclude($this->lastIP->next()->__toString());
}

foreach ($excluded as $network) {
Expand Down Expand Up @@ -214,4 +214,4 @@ public function count(): int
{
return (int) bcadd(bcsub($this->lastIP->toLong(), $this->firstIP->toLong()), '1');
}
}
}
10 changes: 5 additions & 5 deletions tests/IPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testParseBinException(): void
*/
public function testParseLong(): void
{
$ipv4long = '2130706433';
$ipv4long = 2130706433;
$ipv4 = IP::parseLong($ipv4long);

$ipv6Long = '340277174624079928635746076935438991360';
Expand Down Expand Up @@ -197,8 +197,8 @@ public static function getTestConstructorExceptionData(): array
return [
['256.0.0.1'],
['127.-1.0.1'],
[123.45],
[-123.45],
['123.45'],
['-123.45'],
['cake'],
['12345'],
['-12345'],
Expand All @@ -219,7 +219,7 @@ public static function getToStringData(): array
public static function getTestParseData(): array
{
return [
[2130706433, '127.0.0.1'], // long
['2130706433', '127.0.0.1'], // long
['0b01111111000000000000000000000001', '127.0.0.1'], // bin
['0x7f000001', '127.0.0.1'], // hex,
['0x20010000000000008000000000000000', '2001::8000:0:0:0'], // hex
Expand Down Expand Up @@ -270,4 +270,4 @@ public static function getReversePointerData(): array
['2001:db8::567:89ab', 'b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'],
];
}
}
}

0 comments on commit af21061

Please sign in to comment.