Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ext-bcmath": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "^13.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 9 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/13.0/phpunit.xsd"
colors="true"
executionOrder="depends,defects"
backupGlobals="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
cacheDirectory=".phpunit.cache">

<php>
<ini name="error_reporting" value="-1"/>
</php>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<coverage>
<report>
<html outputDirectory="tests/var/coverage-report" lowUpperBound="35" highLowerBound="70"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
Expand All @@ -27,4 +23,10 @@
<directory>tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
43 changes: 15 additions & 28 deletions tests/IPTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use IPTools\IP;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class IPTest extends TestCase
Expand All @@ -24,9 +25,7 @@ public function testConstructor(): void
$this->assertEquals(IP::IP_V6_OCTETS, $ipv6->getOctetsCount());
}

/**
* @dataProvider getTestConstructorExceptionData
*/
#[DataProvider('getTestConstructorExceptionData')]
public function testConstructorException($string): void
{
$this->expectException(\Exception::class);
Expand All @@ -48,27 +47,21 @@ public function testProperties(): void
$this->assertNotEmpty($ip->hex);
}

/**
* @dataProvider getToStringData
*/
#[DataProvider('getToStringData')]
public function testToString($actual, $expected): void
{
$ip = new IP($actual);
$this->assertEquals($expected, (string)$ip);
}

/**
* @dataProvider getTestParseData
*/
#[DataProvider('getTestParseData')]
public function testParse($ipString, $expected): void
{
$ip = IP::parse($ipString);
$this->assertEquals($expected, (string) $ip);
}

/**
* @dataProvider getParseBinData
*/
#[DataProvider('getParseBinData')]
public function testParseBin($bin, $expectedString): void
{
$ip = IP::parseBin($bin);
Expand Down Expand Up @@ -131,9 +124,7 @@ public function testParseInAddr(): void
$this->assertEquals($inAddr, $ip->inAddr());
}

/**
* @dataProvider getTestNextData
*/
#[DataProvider('getTestNextData')]
public function testNext($ip, $step, $expected): void
{
$object = new IP($ip);
Expand All @@ -142,9 +133,7 @@ public function testNext($ip, $step, $expected): void
$this->assertEquals($expected, (string) $next);
}

/**
* @dataProvider getTestPrevData
*/
#[DataProvider('getTestPrevData')]
public function testPrev($ip, $step, $expected): void
{
$object = new IP($ip);
Expand All @@ -163,17 +152,15 @@ public function testPrevException(): void
$object->prev(-1);
}

/**
* @dataProvider getReversePointerData
*/
#[DataProvider('getReversePointerData')]
public function testReversePointer($ip, $expected): void
{
$object = new IP($ip);
$reversePointer = $object->getReversePointer();
$this->assertEquals($expected, $reversePointer);
}

public function getTestConstructorExceptionData(): array
public static function getTestConstructorExceptionData(): array
{
return [
['256.0.0.1'],
Expand All @@ -187,7 +174,7 @@ public function getTestConstructorExceptionData(): array
];
}

public function getToStringData(): array
public static function getToStringData(): array
{
return [
['127.0.0.1', '127.0.0.1'],
Expand All @@ -197,7 +184,7 @@ public function getToStringData(): array
];
}

public function getTestParseData(): array
public static function getTestParseData(): array
{
return [
[2130706433, '127.0.0.1'], //long
Expand All @@ -209,7 +196,7 @@ public function getTestParseData(): array
];
}

public function getParseBinData(): array
public static function getParseBinData(): array
{
return [
[
Expand All @@ -220,7 +207,7 @@ public function getParseBinData(): array
];
}

public function getTestNextData(): array
public static function getTestNextData(): array
{
return [
['192.168.0.1', 1, '192.168.0.2'],
Expand All @@ -232,7 +219,7 @@ public function getTestNextData(): array
];
}

public function getTestPrevData(): array
public static function getTestPrevData(): array
{
return [
['192.168.1.1', 1, '192.168.1.0'],
Expand All @@ -244,7 +231,7 @@ public function getTestPrevData(): array
];
}

public function getReversePointerData(): array
public static function getReversePointerData(): array
{
return [
['192.0.2.5', '5.2.0.192.in-addr.arpa'],
Expand Down
61 changes: 21 additions & 40 deletions tests/NetworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use IPTools\Network;
use IPTools\IP;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class NetworkTest extends TestCase
Expand Down Expand Up @@ -34,9 +35,7 @@ public function testProperties(): void
$this->assertEquals('192.0.0.255', (string)$network->lastIP);
}

/**
* @dataProvider getTestParseData
*/
#[DataProvider('getTestParseData')]
public function testParse($data, $expected): void
{
$this->assertEquals($expected, (string)Network::parse($data));
Expand All @@ -50,9 +49,7 @@ public function testParseWrongNetwork(): void
Network::parse('10.0.0.0/24 abc');
}

/**
* @dataProvider getPrefixData
*/
#[DataProvider('getPrefixData')]
public function testPrefix2Mask($prefix, $version, $mask): void
{
$this->assertEquals($mask, Network::prefix2netmask($prefix, $version));
Expand All @@ -66,9 +63,7 @@ public function testPrefix2MaskWrongIPVersion(): void
Network::prefix2netmask('128', 'ip_version');
}

/**
* @dataProvider getInvalidPrefixData
*/
#[DataProvider('getInvalidPrefixData')]
public function testPrefix2MaskInvalidPrefix($prefix, $version): void
{
$this->expectException(\Exception::class);
Expand All @@ -77,9 +72,7 @@ public function testPrefix2MaskInvalidPrefix($prefix, $version): void
Network::prefix2netmask($prefix, $version);
}

/**
* @dataProvider getHostsData
*/
#[DataProvider('getHostsData')]
public function testHosts($data, $expected): void
{
$result = [];
Expand All @@ -91,9 +84,7 @@ public function testHosts($data, $expected): void
$this->assertEquals($expected, $result);
}

/**
* @dataProvider getExcludeData
*/
#[DataProvider('getExcludeData')]
public function testExclude($data, $exclude, $expected): void
{
$result = array();
Expand All @@ -105,9 +96,7 @@ public function testExclude($data, $exclude, $expected): void
$this->assertEquals($expected, $result);
}

/**
* @dataProvider getExcludeExceptionData
*/
#[DataProvider('getExcludeExceptionData')]
public function testExcludeException($data, $exclude): void
{
$this->expectException(\Exception::class);
Expand All @@ -116,9 +105,7 @@ public function testExcludeException($data, $exclude): void
Network::parse($data)->exclude($exclude);
}

/**
* @dataProvider getMoveToData
*/
#[DataProvider('getMoveToData')]
public function testMoveTo($network, $prefixLength, $expected): void
{
$result = array();
Expand All @@ -130,9 +117,7 @@ public function testMoveTo($network, $prefixLength, $expected): void
$this->assertEquals($expected, $result);
}

/**
* @dataProvider getMoveToExceptionData
*/
#[DataProvider('getMoveToExceptionData')]
public function testMoveToException($network, $prefixLength): void
{
$this->expectException(\Exception::class);
Expand All @@ -141,9 +126,7 @@ public function testMoveToException($network, $prefixLength): void
Network::parse($network)->moveTo($prefixLength);
}

/**
* @dataProvider getTestIterationData
*/
#[DataProvider('getTestIterationData')]
public function testNetworkIteration($data, $expected): void
{
$result = [];
Expand All @@ -155,15 +138,13 @@ public function testNetworkIteration($data, $expected): void
$this->assertEquals($expected, $result);
}

/**
* @dataProvider getTestCountData
*/
#[DataProvider('getTestCountData')]
public function testCount($data, $expected): void
{
$this->assertCount($expected, Network::parse($data));
}

public function getTestParseData(): array
public static function getTestParseData(): array
{
return [
['192.168.0.54/24', '192.168.0.0/24'],
Expand All @@ -173,7 +154,7 @@ public function getTestParseData(): array
];
}

public function getPrefixData(): array
public static function getPrefixData(): array
{
return [
['24', IP::IP_V4, IP::parse('255.255.255.0')],
Expand All @@ -183,7 +164,7 @@ public function getPrefixData(): array
];
}

public function getInvalidPrefixData(): array
public static function getInvalidPrefixData(): array
{
return [
['-1', IP::IP_V4],
Expand All @@ -193,7 +174,7 @@ public function getInvalidPrefixData(): array
];
}

public function getHostsData(): array
public static function getHostsData(): array
{
return [
[
Expand All @@ -210,7 +191,7 @@ public function getHostsData(): array
];
}

public function getExcludeData(): array
public static function getExcludeData(): array
{
return [
[
Expand All @@ -226,15 +207,15 @@ public function getExcludeData(): array
];
}

public function getExcludeExceptionData(): array
public static function getExcludeExceptionData(): array
{
return [
['192.0.2.0/28', '192.0.3.0/24'],
['192.0.2.2/32', '192.0.2.3/32'],
];
}

public function getMoveToData(): array
public static function getMoveToData(): array
{
return [
[
Expand Down Expand Up @@ -265,7 +246,7 @@ public function getMoveToData(): array
];
}

public function getMoveToExceptionData(): array
public static function getMoveToExceptionData(): array
{
return [
['192.168.0.0/22', '22'],
Expand All @@ -275,7 +256,7 @@ public function getMoveToExceptionData(): array
];
}

public function getTestIterationData(): array
public static function getTestIterationData(): array
{
return [
[
Expand Down Expand Up @@ -307,7 +288,7 @@ public function getTestIterationData(): array
];
}

public function getTestCountData(): array
public static function getTestCountData(): array
{
return [
['127.0.0.0/31', 2],
Expand Down
Loading