Completed
Push — master ( 502ebf...ce3a1d )
by Jeroen De
192:28 queued 171:53
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
declare( strict_types = 1 );
4
5
namespace Tests\DataValues\Geo\Parsers;
6
7
use DataValues\Geo\Parsers\FloatCoordinateParser;
8
use DataValues\Geo\Values\LatLongValue;
9
10
/**
11
 * @covers \DataValues\Geo\Parsers\FloatCoordinateParser
12
 * @covers \DataValues\Geo\Parsers\LatLongParserBase
13
 *
14
 * @group ValueParsers
15
 * @group DataValueExtensions
16
 *
17
 * @license GPL-2.0-or-later
18
 * @author Jeroen De Dauw < [email protected] >
19
 */
20
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...
21
22
	/**
23
	 * @see ValueParserTestBase::getInstance
24
	 *
25
	 * @return FloatCoordinateParser
26
	 */
27
	protected function getInstance() {
28
		return new FloatCoordinateParser();
29
	}
30
31
	/**
32
	 * @see ValueParserTestBase::validInputProvider
33
	 */
34
	public function validInputProvider() {
35
		$argLists = [];
36
37
		// TODO: test with different parser options
38
39
		$valid = [
40
			// Whitespace
41
			"1N 1E\n" => [ 1, 1 ],
42
			' 1N 1E ' => [ 1, 1 ],
43
44
			'55.7557860 N, 37.6176330 W' => [ 55.7557860, -37.6176330 ],
45
			'55.7557860, -37.6176330' => [ 55.7557860, -37.6176330 ],
46
			'55 S, 37.6176330 W' => [ -55, -37.6176330 ],
47
			'-55, -37.6176330' => [ -55, -37.6176330 ],
48
			'5.5S,37W ' => [ -5.5, -37 ],
49
			'-5.5,-37 ' => [ -5.5, -37 ],
50
			'4,2' => [ 4, 2 ],
51
52
			// Coordinate strings without separator:
53
			'55.7557860 N 37.6176330 W' => [ 55.7557860, -37.6176330 ],
54
			'55.7557860 -37.6176330' => [ 55.7557860, -37.6176330 ],
55
			'55 S 37.6176330 W' => [ -55, -37.6176330 ],
56
			'-55 -37.6176330' => [ -55, -37.6176330 ],
57
			'5.5S 37W ' => [ -5.5, -37 ],
58
			'-5.5 -37 ' => [ -5.5, -37 ],
59
			'4 2' => [ 4, 2 ],
60
61
			// Coordinate string starting with direction character:
62
			'S5.5 W37 ' => [ -5.5, -37 ],
63
			'N 5.5 E 37 ' => [ 5.5, 37 ],
64
		];
65
66
		foreach ( $valid as $value => $expected ) {
67
			$expected = new LatLongValue( $expected[0], $expected[1] );
68
			$argLists[] = [ (string)$value, $expected ];
69
		}
70
71
		return $argLists;
72
	}
73
74
	/**
75
	 * @see StringValueParserTest::invalidInputProvider
76
	 */
77
	public function invalidInputProvider() {
78
		return [
79
			[ null ],
80
			[ 1 ],
81
			[ 0.1 ],
82
			[ '~=[,,_,,]:3' ],
83
			[ 'ohi there' ],
84
		];
85
	}
86
87
}
88