Skip to content

Commit

Permalink
PHPStan Coverage for Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zanbaldwin committed Mar 28, 2024
1 parent 762dde4 commit e77913a
Show file tree
Hide file tree
Showing 26 changed files with 814 additions and 98 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
level: 'max'
paths: [ 'src' ]
paths: [ 'src', 'tests' ]
checkFunctionNameCase: true
checkGenericClassInNonGenericObjectType: true
reportUnmatchedIgnoredErrors: true
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/ConsistentFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function ntopVersion4($binary)
// $pack return type is `string|false` below PHP 8 and `string`
// above PHP 8.
$pack = \pack('A4', $binary);
// @phpstan-ignore-next-line identical.alwaysFalse
/** @phpstan-ignore identical.alwaysFalse */

Check failure on line 76 in src/Formatter/ConsistentFormatter.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Unknown PHPDoc tag: @phpstan-ignore
if (false === $pack || false === $protocol = \inet_ntop($pack)) {

Check failure on line 77 in src/Formatter/ConsistentFormatter.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Strict comparison using === between false and string will always evaluate to false.
throw new FormatException($binary);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/NativeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function ntop($binary)
$pack = \pack(\sprintf('A%d', $length), $binary);
// $pack return type is `string|false` below PHP 8 and `string`
// above PHP 8.
// @phpstan-ignore-next-line identical.alwaysFalse
/** @phpstan-ignore identical.alwaysFalse */

Check failure on line 21 in src/Formatter/NativeFormatter.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Unknown PHPDoc tag: @phpstan-ignore
if (false === $pack || false === $protocol = \inet_ntop($pack)) {

Check failure on line 22 in src/Formatter/NativeFormatter.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Strict comparison using === between false and string will always evaluate to false.
throw new FormatException($binary);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/DataProvider/Formatter/ConsistentFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class ConsistentFormatter
{
/** @return list<array{string, string}> */
public static function getValidBinarySequences()
{
return [
Expand Down Expand Up @@ -33,6 +34,7 @@ public static function getValidBinarySequences()
];
}

/** @return list<array{mixed}> */
public static function getInvalidBinarySequences()
{
return [
Expand Down
2 changes: 2 additions & 0 deletions tests/DataProvider/Formatter/NativeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class NativeFormatter
{
/** @return list<array{string, string}> */
public static function getValidBinarySequences()
{
return [
Expand Down Expand Up @@ -32,6 +33,7 @@ public static function getValidBinarySequences()
];
}

/** @return list<array{mixed}> */
public static function getInvalidBinarySequences()
{
return [
Expand Down
21 changes: 21 additions & 0 deletions tests/DataProvider/IPv4.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class IPv4 implements IpDataProviderInterface
{
/** @return list<array{string, string, string}> */
public static function getValidBinarySequences()
{
return [
Expand All @@ -23,6 +24,7 @@ public static function getValidBinarySequences()
];
}

/** @return list<array{string, string, string}> */
public static function getValidProtocolIpAddresses()
{
return [
Expand All @@ -41,11 +43,13 @@ public static function getValidProtocolIpAddresses()
];
}

/** @return list<array{string, string, string}> */
public static function getValidIpAddresses()
{
return array_merge(self::getValidBinarySequences(), self::getValidProtocolIpAddresses());
}

/** @return list<array{mixed}> */
public static function getInvalidIpAddresses()
{
return [
Expand All @@ -67,6 +71,7 @@ public static function getInvalidIpAddresses()
];
}

/** @return list<array{int, string}> */
public static function getValidCidrValues()
{
return [
Expand All @@ -82,6 +87,7 @@ public static function getValidCidrValues()
];
}

/** @return list<array{mixed}> */
public static function getInvalidCidrValues()
{
return [
Expand All @@ -97,6 +103,7 @@ public static function getInvalidCidrValues()
];
}

/** @return list<array{string, int}> */
public static function getNetworkIpAddresses()
{
return [
Expand All @@ -109,6 +116,7 @@ public static function getNetworkIpAddresses()
];
}

/** @return list<array{string, int}> */
public static function getBroadcastIpAddresses()
{
return [
Expand All @@ -121,6 +129,7 @@ public static function getBroadcastIpAddresses()
];
}

/** @return list<array{string, string, int}> */
public static function getValidInRangeIpAddresses()
{
return [
Expand All @@ -131,6 +140,7 @@ public static function getValidInRangeIpAddresses()
];
}

/** @return list<array{string, string, int}> */
public static function getCommonCidrValues()
{
return [
Expand All @@ -153,56 +163,67 @@ public static function getCommonCidrValues()
];
}

/** @return list<array{string, bool}> */
public static function getLinkLocalIpAddresses()
{
return self::getCategoryOfIpAddresses(self::LINK_LOCAL);
}

/** @return list<array{string, bool}> */
public static function getLoopbackIpAddresses()
{
return self::getCategoryOfIpAddresses(self::LOOPBACK);
}

/** @return list<array{string, bool}> */
public static function getMulticastIpAddresses()
{
return self::getCategoryOfIpAddresses(self::MULTICAST);
}

/** @return list<array{string, bool}> */
public static function getPrivateUseIpAddresses()
{
return self::getCategoryOfIpAddresses(self::PRIVATE_USE);
}

/** @return list<array{string, bool}> */
public static function getUnspecifiedIpAddresses()
{
return self::getCategoryOfIpAddresses(self::UNSPECIFIED);
}

/** @return list<array{string, bool}> */
public static function getBenchmarkingIpAddresses()
{
return self::getCategoryOfIpAddresses(self::BENCHMARKING);
}

/** @return list<array{string, bool}> */
public static function getDocumentationIpAddresses()
{
return self::getCategoryOfIpAddresses(self::DOCUMENTATION);
}

/** @return list<array{string, bool}> */
public static function getPublicUseIpAddresses()
{
return self::getCategoryOfIpAddresses(self::PUBLIC_USE_V4);
}

/** @return list<array{string, bool}> */
public static function getIsBroadcastIpAddresses()
{
return self::getCategoryOfIpAddresses(self::BROADCAST);
}

/** @return list<array{string, bool}> */
public static function getSharedIpAddresses()
{
return self::getCategoryOfIpAddresses(self::SHARED);
}

/** @return list<array{string, bool}> */
public static function getFutureReservedIpAddresses()
{
return self::getCategoryOfIpAddresses(self::FUTURE_RESERVED);
Expand Down
28 changes: 28 additions & 0 deletions tests/DataProvider/IPv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class IPv6 implements IpDataProviderInterface
{
/** @return list<array{string, string, string, string}> */
public static function getValidBinarySequences()
{
return [
Expand All @@ -23,6 +24,7 @@ public static function getValidBinarySequences()
];
}

/** @return list<array{string, string, string, string}> */
public static function getValidProtocolIpAddresses()
{
return [
Expand All @@ -40,11 +42,13 @@ public static function getValidProtocolIpAddresses()
];
}

/** @return list<array{string, string, string, string}> */
public static function getValidIpAddresses()
{
return array_merge(self::getValidBinarySequences(), self::getValidProtocolIpAddresses());
}

/** @return list<array{mixed}> */
public static function getInvalidIpAddresses()
{
return [
Expand All @@ -67,6 +71,7 @@ public static function getInvalidIpAddresses()
];
}

/** @return list<array{int, string}> */
public static function getValidCidrValues()
{
return [
Expand All @@ -81,6 +86,7 @@ public static function getValidCidrValues()
];
}

/** @return list<array{mixed}> */
public static function getInvalidCidrValues()
{
return [
Expand All @@ -96,6 +102,7 @@ public static function getInvalidCidrValues()
];
}

/** @return list<array{string, int}> */
public static function getNetworkIpAddresses()
{
return [
Expand All @@ -107,6 +114,7 @@ public static function getNetworkIpAddresses()
];
}

/** @return list<array{string, int}> */
public static function getBroadcastIpAddresses()
{
return [
Expand All @@ -118,6 +126,7 @@ public static function getBroadcastIpAddresses()
];
}

/** @return list<array{string, string, int}> */
public static function getValidInRangeIpAddresses()
{
return [
Expand All @@ -130,6 +139,7 @@ public static function getValidInRangeIpAddresses()
];
}

/** @return list<array{string, string, int}> */
public static function getCommonCidrValues()
{
return [
Expand All @@ -152,61 +162,73 @@ public static function getCommonCidrValues()
];
}

/** @return list<array{string, bool}> */
public static function getMappedIpAddresses()
{
return self::getCategoryOfIpAddresses(self::MAPPED);
}

/** @return list<array{string, bool}> */
public static function getDerivedIpAddresses()
{
return self::getCategoryOfIpAddresses(self::DERIVED);
}

/** @return list<array{string, bool}> */
public static function getCompatibleIpAddresses()
{
return self::getCategoryOfIpAddresses(self::COMPATIBLE);
}

/** @return list<array{string, bool}> */
public static function getLinkLocalIpAddresses()
{
return self::getCategoryOfIpAddresses(self::LINK_LOCAL);
}

/** @return list<array{string, bool}> */
public static function getLoopbackIpAddresses()
{
return self::getCategoryOfIpAddresses(self::LOOPBACK);
}

/** @return list<array{string, bool}> */
public static function getMulticastIpAddresses()
{
return self::getCategoryOfIpAddresses(self::MULTICAST);
}

/** @return list<array{string, bool}> */
public static function getPrivateUseIpAddresses()
{
return self::getCategoryOfIpAddresses(self::PRIVATE_USE);
}

/** @return list<array{string, bool}> */
public static function getUnspecifiedIpAddresses()
{
return self::getCategoryOfIpAddresses(self::UNSPECIFIED);
}

/** @return list<array{string, bool}> */
public static function getBenchmarkingIpAddresses()
{
return self::getCategoryOfIpAddresses(self::BENCHMARKING);
}

/** @return list<array{string, bool}> */
public static function getDocumentationIpAddresses()
{
return self::getCategoryOfIpAddresses(self::DOCUMENTATION);
}

/** @return list<array{string, bool}> */
public static function getPublicUseIpAddresses()
{
return self::getCategoryOfIpAddresses(self::PUBLIC_USE_V6);
}

/** @return list<array{string, bool}> */
public static function getPublicUseIpAddressesExcludingMapped()
{
// Exclude IPv4-embedded addresses embedded using the Mapped strategy,
Expand All @@ -215,31 +237,37 @@ public static function getPublicUseIpAddressesExcludingMapped()
return self::getCategoryOfIpAddresses(self::PUBLIC_USE_V6, self::MAPPED);
}

/** @return list<array{string, bool}> */
public static function getUniqueLocalIpAddresses()
{
return self::getCategoryOfIpAddresses(self::UNIQUE_LOCAL);
}

/** @return list<array{string, bool}> */
public static function getUniqueLocalIpAddressesExcludingMapped()
{
return self::getCategoryOfIpAddresses(self::UNIQUE_LOCAL, self::MAPPED);
}

/** @return list<array{string, bool}> */
public static function getUnicastIpAddresses()
{
return self::getCategoryOfIpAddresses(self::UNICAST);
}

/** @return list<array{string, bool}> */
public static function getUnicastIpAddressesExcludingMapped()
{
return self::getCategoryOfIpAddresses(self::UNICAST, self::MAPPED);
}

/** @return list<array{string, bool}> */
public static function getUnicastGlobalIpAddresses()
{
return self::getCategoryOfIpAddresses(self::UNICAST_GLOBAL);
}

/** @return list<array{string, bool}> */
public static function getUnicastGlobalIpAddressesExcludingMapped()
{
return self::getCategoryOfIpAddresses(self::UNICAST_GLOBAL, self::MAPPED);
Expand Down
Loading

0 comments on commit e77913a

Please sign in to comment.