Skip to content

Commit

Permalink
fix(tests): update IPv6 test to align with PHP 8.4.3 behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
xHeaven authored Jan 23, 2025
1 parent 0214ac3 commit dec5c2f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/Tempest/Validation/src/Rules/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ public function __construct(
private bool $allowPrivateRange = true,
private bool $allowReservedRange = true,
) {
$options = 0;
$options = $options | FILTER_FLAG_IPV4;
$options = $options | FILTER_FLAG_IPV6;
$options = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;

if (! $this->allowPrivateRange) {
$options = $options | FILTER_FLAG_NO_PRIV_RANGE;
$options |= FILTER_FLAG_NO_PRIV_RANGE;
}

if (! $this->allowReservedRange) {
$options = $options | FILTER_FLAG_NO_RES_RANGE;
$options |= FILTER_FLAG_NO_RES_RANGE;
}

$this->options = $options;
Expand Down
7 changes: 3 additions & 4 deletions src/Tempest/Validation/src/Rules/IPv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ public function __construct(
private bool $allowPrivateRange = true,
private bool $allowReservedRange = true,
) {
$options = 0;
$options = $options | FILTER_FLAG_IPV4;
$options = FILTER_FLAG_IPV4;

if (! $this->allowPrivateRange) {
$options = $options | FILTER_FLAG_NO_PRIV_RANGE;
$options |= FILTER_FLAG_NO_PRIV_RANGE;
}

if (! $this->allowReservedRange) {
$options = $options | FILTER_FLAG_NO_RES_RANGE;
$options |= FILTER_FLAG_NO_RES_RANGE;
}

$this->options = $options;
Expand Down
7 changes: 3 additions & 4 deletions src/Tempest/Validation/src/Rules/IPv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ public function __construct(
private bool $allowPrivateRange = true,
private bool $allowReservedRange = true,
) {
$options = 0;
$options = $options | FILTER_FLAG_IPV6;
$options = FILTER_FLAG_IPV6;

if (! $this->allowPrivateRange) {
$options = $options | FILTER_FLAG_NO_PRIV_RANGE;
$options |= FILTER_FLAG_NO_PRIV_RANGE;
}

if (! $this->allowReservedRange) {
$options = $options | FILTER_FLAG_NO_RES_RANGE;
$options |= FILTER_FLAG_NO_RES_RANGE;
}

$this->options = $options;
Expand Down
8 changes: 1 addition & 7 deletions src/Tempest/Validation/tests/Rules/IPv6Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ public function test_ip_address_without_private_range(): void

public function test_ip_address_without_reserved_range(): void
{
if (PHP_OS_FAMILY === 'Windows') {
$this->markTestSkipped('Some kind of problem with Windows. Needs further investigation.');
/** @phpstan-ignore-next-line */
return;
}

$rule = new IPv6(allowReservedRange: false);
$this->assertFalse($rule->isValid('2001:db8:ffff:ffff:ffff:ffff:ffff:ffff'));
$this->assertFalse($rule->isValid('::1'));
$this->assertTrue($rule->isValid('2a03:b0c0:3:d0::11f5:3001'));

$rule = new IPv6(allowReservedRange: true);
Expand Down

0 comments on commit dec5c2f

Please sign in to comment.