Passed
Push — master ( 6e37f8...05a985 )
by Jeroen De
02:43
created

tests/unit/Parsers/FloatCoordinateParserTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Tests\DataValues\Geo\Parsers;
4
5
use DataValues\Geo\Parsers\FloatCoordinateParser;
6
use DataValues\Geo\Values\LatLongValue;
7
8
/**
9
 * @covers DataValues\Geo\Parsers\FloatCoordinateParser
10
 *
11
 * @group ValueParsers
12
 * @group DataValueExtensions
13
 *
14
 * @license GPL-2.0+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class FloatCoordinateParserTest extends ParserTestBase {
0 ignored issues
show
Deprecated Code introduced by
The class Tests\DataValues\Geo\Parsers\ParserTestBase has been deprecated with message: This is a copy of ValueParserTestBase from DataValues Common, temporarily created to
be able to refactor it away in easy to follow steps.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
18
19
	/**
20
	 * @see ValueParserTestBase::getInstance
21
	 *
22
	 * @return FloatCoordinateParser
23
	 */
24
	protected function getInstance() {
25
		return new FloatCoordinateParser();
26
	}
27
28
	/**
29
	 * @see ValueParserTestBase::validInputProvider
30
	 */
31
	public function validInputProvider() {
32
		$argLists = [];
33
34
		// TODO: test with different parser options
35
36
		$valid = [
37
			// Whitespace
38
			"1N 1E\n" => [ 1, 1 ],
39
			' 1N 1E ' => [ 1, 1 ],
40
41
			'55.7557860 N, 37.6176330 W' => [ 55.7557860, -37.6176330 ],
42
			'55.7557860, -37.6176330' => [ 55.7557860, -37.6176330 ],
43
			'55 S, 37.6176330 W' => [ -55, -37.6176330 ],
44
			'-55, -37.6176330' => [ -55, -37.6176330 ],
45
			'5.5S,37W ' => [ -5.5, -37 ],
46
			'-5.5,-37 ' => [ -5.5, -37 ],
47
			'4,2' => [ 4, 2 ],
48
49
			// Coordinate strings without separator:
50
			'55.7557860 N 37.6176330 W' => [ 55.7557860, -37.6176330 ],
51
			'55.7557860 -37.6176330' => [ 55.7557860, -37.6176330 ],
52
			'55 S 37.6176330 W' => [ -55, -37.6176330 ],
53
			'-55 -37.6176330' => [ -55, -37.6176330 ],
54
			'5.5S 37W ' => [ -5.5, -37 ],
55
			'-5.5 -37 ' => [ -5.5, -37 ],
56
			'4 2' => [ 4, 2 ],
57
58
			// Coordinate string starting with direction character:
59
			'S5.5 W37 ' => [ -5.5, -37 ],
60
			'N 5.5 E 37 ' => [ 5.5, 37 ],
61
		];
62
63
		foreach ( $valid as $value => $expected ) {
64
			$expected = new LatLongValue( $expected[0], $expected[1] );
65
			$argLists[] = [ (string)$value, $expected ];
66
		}
67
68
		return $argLists;
69
	}
70
71
	/**
72
	 * @see StringValueParserTest::invalidInputProvider
73
	 */
74
	public function invalidInputProvider() {
75
		return [
76
			[ null ],
77
			[ 1 ],
78
			[ 0.1 ],
79
			[ '~=[,,_,,]:3' ],
80
			[ 'ohi there' ],
81
		];
82
	}
83
84
}
85