Skip to content

Commit 3cdf3fd

Browse files
committed
Add tests for Util class
Signed-off-by: Michal Čihař <[email protected]>
1 parent 1bcc068 commit 3cdf3fd

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/UtilTest.php

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

0 commit comments

Comments
 (0)