File: UtilTest.php

package info (click to toggle)
phpmyadmin-shapefile 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,436 kB
  • sloc: php: 1,630; makefile: 7
file content (85 lines) | stat: -rw-r--r-- 2,074 bytes parent folder | download
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
<?php

declare(strict_types=1);

/**
 * phpMyAdmin ShapeFile library
 * <https://github.com/phpmyadmin/shapefile/>.
 *
 * Copyright 2016 - 2017 Michal Čihař <michal@cihar.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can download one from
 * https://www.gnu.org/copyleft/gpl.html.
 */

namespace PhpMyAdminTest\ShapeFile;

use PhpMyAdmin\ShapeFile\Util;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class UtilTest extends TestCase
{
    /**
     * Test data loading.
     *
     * @param string       $type     Data type
     * @param string|false $data     Data to parse
     * @param string|false $expected Expected result
     */
    #[DataProvider('data')]
    public function testLoadData(string $type, $data, $expected): void
    {
        $this->assertEquals(
            $expected,
            Util::loadData($type, $data)
        );
    }

    /**
     * Data provider for loadData tests.
     *
     * @return array
     */
    public static function data(): array
    {
        return [
            [
                'N',
                '',
                false,
            ],
            [
                'N',
                false,
                false,
            ],
            [
                'N',
                "\x01\x02\x03\x04",
                0x01020304,
            ],
        ];
    }

    /**
     * Test for byte order changes.
     */
    public function testSwap(): void
    {
        $this->assertEquals(
            "\x01\x02\x03\x04",
            Util::swap("\x04\x03\x02\x01")
        );
    }
}