Passed
Push — master ( 22923d...e0306a )
by Maurício
01:57
created

UtilTest::testSwap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * phpMyAdmin ShapeFile library
7
 * <https://github.com/phpmyadmin/shapefile/>.
8
 *
9
 * Copyright 2016 - 2017 Michal Čihař <[email protected]>
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, you can download one from
22
 * https://www.gnu.org/copyleft/gpl.html.
23
 */
24
25
namespace PhpMyAdminTest\ShapeFile;
26
27
use PhpMyAdmin\ShapeFile\Util;
28
use PHPUnit\Framework\TestCase;
29
30
class UtilTest extends TestCase
31
{
32
    /**
33
     * Test data loading.
34
     *
35
     * @param string       $type     Data type
36
     * @param string|false $data     Data to parse
37
     * @param string|false $expected Expected result
38
     *
39
     * @dataProvider data
40
     */
41
    public function testLoadData(string $type, $data, $expected): void
42
    {
43
        $this->assertEquals(
44
            $expected,
45
            Util::loadData($type, $data)
46
        );
47
    }
48
49
    /**
50
     * Data provider for loadData tests.
51
     *
52
     * @return array
53
     */
54
    public static function data(): array
55
    {
56
        return [
57
            [
58
                'N',
59
                '',
60
                false,
61
            ],
62
            [
63
                'N',
64
                false,
65
                false,
66
            ],
67
            [
68
                'N',
69
                "\x01\x02\x03\x04",
70
                0x01020304,
71
            ],
72
        ];
73
    }
74
75
    /**
76
     * Test for byte order changes.
77
     */
78
    public function testSwap(): void
79
    {
80
        $this->assertEquals(
81
            "\x01\x02\x03\x04",
82
            Util::swap("\x04\x03\x02\x01")
83
        );
84
    }
85
}
86