Passed
Push — zeroRounding ( 491d2a...2f1015 )
by no
35:13 queued 21:46
created

DmCoordinateParserTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 71
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 3 1
B validInputProvider() 0 37 2
A invalidInputProvider() 0 14 2
1
<?php
2
3
namespace Tests\DataValues\Geo\Parsers;
4
5
use DataValues\Geo\Parsers\DmCoordinateParser;
6
use DataValues\Geo\Values\LatLongValue;
7
use ValueParsers\Test\StringValueParserTest;
8
9
/**
10
 * @covers DataValues\Geo\Parsers\DmCoordinateParser
11
 *
12
 * @group ValueParsers
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class DmCoordinateParserTest extends StringValueParserTest {
19
20
	/**
21
	 * @see ValueParserTestBase::getInstance
22
	 *
23
	 * @return DmCoordinateParser
24
	 */
25
	protected function getInstance() {
26
		return new DmCoordinateParser();
27
	}
28
29
	/**
30
	 * @see ValueParserTestBase::validInputProvider
31
	 */
32
	public function validInputProvider() {
33
		$argLists = [];
34
35
		// TODO: test with different parser options
36
37
		$valid = [
38
			// Whitespace
39
			"1°0'N 1°0'E\n" => [ 1, 1 ],
40
			" 1°0'N 1°0'E " => [ 1, 1 ],
41
42
			"55° 0', 37° 0'" => [ 55, 37 ],
43
			"55° 30', 37° 30'" => [ 55.5, 37.5 ],
44
			"0° 0', 0° 0'" => [ 0, 0 ],
45
			"-55° 30', -37° 30'" => [ -55.5, -37.5 ],
46
			"0° 0.3' S, 0° 0.3' W" => [ -0.005, -0.005 ],
47
			"55° 30′, 37° 30′" => [ 55.5, 37.5 ],
48
49
			// Coordinate strings without separator:
50
			"55° 0' 37° 0'" => [ 55, 37 ],
51
			"55 ° 30 ' 37 ° 30 '" => [ 55.5, 37.5 ],
52
			"0° 0' 0° 0'" => [ 0, 0 ],
53
			"-55° 30 ' -37 ° 30'" => [ -55.5, -37.5 ],
54
			"0° 0.3' S 0° 0.3' W" => [ -0.005, -0.005 ],
55
			"55° 30′ 37° 30′" => [ 55.5, 37.5 ],
56
57
			// Coordinate string starting with direction character:
58
			"S 0° 0.3', W 0° 0.3'" => [ -0.005, -0.005 ],
59
			"N 0° 0.3' E 0° 0.3'" => [ 0.005, 0.005 ],
60
		];
61
62
		foreach ( $valid as $value => $expected ) {
63
			$expected = new LatLongValue( $expected[0], $expected[1] );
64
			$argLists[] = [ (string)$value, $expected ];
65
		}
66
67
		return $argLists;
68
	}
69
70
	/**
71
	 * @see StringValueParserTest::invalidInputProvider
72
	 */
73
	public function invalidInputProvider() {
74
		$argLists = parent::invalidInputProvider();
75
76
		$invalid = [
77
			'~=[,,_,,]:3',
78
			'ohi there',
79
		];
80
81
		foreach ( $invalid as $value ) {
82
			$argLists[] = [ $value ];
83
		}
84
85
		return $argLists;
86
	}
87
88
}
89