1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Utils;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Utils\FormatConverter;
use function hex2bin;
/**
* @covers \PhpMyAdmin\Utils\FormatConverter
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\PhpMyAdmin\Utils\FormatConverter::class)]
class FormatConverterTest extends AbstractTestCase
{
/**
* Test for binaryToIp
*
* @param string $expected Expected result given an input
* @param string $input Input to convert
* @param bool $isBinary The data is binary data
*
* @dataProvider providerBinaryToIp
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinaryToIp')]
public function testBinaryToIp(string $expected, string $input, bool $isBinary): void
{
$result = FormatConverter::binaryToIp($input, $isBinary);
self::assertSame($expected, $result);
}
/**
* Data provider for binaryToIp
*
* @return array
*/
public static function providerBinaryToIp(): array
{
// expected
// input
// isBinary
return [
[
'10.11.12.13',
'0x0a0b0c0d',
false,
],
[
'my ip',
'my ip',
false,
],
[
'10.11.12.13',
'0x0a0b0c0d',
true,
],
[
'6d79206970',
'my ip',
true,
],
[
'10.11.12.13',
'0x0a0b0c0d',
true,
],
[
'666566',
'fef',
true,
],
[
'0ded',
hex2bin('0DED'),
true,
],
[
'127.0.0.1',
hex2bin('30783766303030303031'),
true,
],
];
}
/**
* Test for ipToBinary
*
* @param string $expected Expected result given an input
* @param string $input Input to convert
*
* @dataProvider providerIpToBinary
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerIpToBinary')]
public function testIpToBinary(string $expected, string $input): void
{
$result = FormatConverter::ipToBinary($input);
self::assertSame($expected, $result);
}
/**
* Data provider for ipToBinary
*
* @return array
*/
public static function providerIpToBinary(): array
{
return [
[
'0x0a0b0c0d',
'10.11.12.13',
],
[
'my ip',
'my ip',
],
];
}
/**
* Test for ipToLong
*
* @param string $expected Expected result given an input
* @param string $input Input to convert
*
* @dataProvider providerIpToLong
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerIpToLong')]
public function testIpToLong(string $expected, string $input): void
{
$result = FormatConverter::ipToLong($input);
self::assertEquals($expected, $result);
}
/**
* Data provider for ipToLong
*
* @return array
*/
public static function providerIpToLong(): array
{
return [
[
'168496141',
'10.11.12.13',
],
[
'my ip',
'my ip',
],
];
}
/**
* Test for longToIp
*
* @param string $expected Expected result given an input
* @param string $input Input to convert
*
* @dataProvider providerLongToIp
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerLongToIp')]
public function testLongToIp(string $expected, string $input): void
{
$result = FormatConverter::longToIp($input);
self::assertSame($expected, $result);
}
/**
* Data provider for longToIp
*
* @return array
*/
public static function providerLongToIp(): array
{
return [
[
'10.11.12.13',
'168496141',
],
[
'my ip',
'my ip',
],
];
}
}
|