Passed
Push — master ( f7afdf...759093 )
by Jeroen De
02:45
created

testConstructorThrowsExceptionWhenParametersAreInvalid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Tests\DataValues\Geo\Values;
4
5
use DataValues\Geo\Values\LatLongValue;
6
7
/**
8
 * @covers \DataValues\Geo\Values\LatLongValue
9
 *
10
 * @group DataValue
11
 * @group DataValueExtensions
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class LatLongValueTest extends DataValueTest {
17
18
	/**
19
	 * @see DataValueTest::getClass
20
	 *
21
	 * @return string
22
	 */
23
	public function getClass() {
24
		return LatLongValue::class;
25
	}
26
27
	public function validConstructorArgumentsProvider() {
28
		$argLists = [];
29
30
		$argLists[] = [ 4.2, 4.2 ];
31
		$argLists[] = [ 4.2, 42 ];
32
		$argLists[] = [ 42, 4.2 ];
33
		$argLists[] = [ 42, 42 ];
34
		$argLists[] = [ -4.2, -4.2 ];
35
		$argLists[] = [ 4.2, -42 ];
36
		$argLists[] = [ -42, 4.2 ];
37
		$argLists[] = [ 360, -360 ];
38
		$argLists[] = [ 48.269, -225.99 ];
39
		$argLists[] = [ 0, 0 ];
40
41
		return $argLists;
42
	}
43
44
	public function invalidConstructorArgumentsProvider() {
45
		$argLists = [];
46
47
		$argLists[] = [ -361, 0 ];
48
		$argLists[] = [ -999, 1 ];
49
		$argLists[] = [ 360.001, 2 ];
50
		$argLists[] = [ 3, 361 ];
51
		$argLists[] = [ 4, -1337 ];
52
53
		return $argLists;
54
	}
55
56
	/**
57
	 * @dataProvider instanceProvider
58
	 * @param LatLongValue $latLongValue
59
	 * @param array $arguments
60
	 */
61
	public function testGetLatitude( LatLongValue $latLongValue, array $arguments ) {
62
		$actual = $latLongValue->getLatitude();
63
64
		$this->assertInternalType( 'float', $actual );
65
		$this->assertSame( (float)$arguments[0], $actual );
66
	}
67
68
	/**
69
	 * @dataProvider instanceProvider
70
	 * @param LatLongValue $latLongValue
71
	 * @param array $arguments
72
	 */
73
	public function testGetLongitude( LatLongValue $latLongValue, array $arguments ) {
74
		$actual = $latLongValue->getLongitude();
75
76
		$this->assertInternalType( 'float', $actual );
77
		$this->assertSame( (float)$arguments[1], $actual );
78
	}
79
80
	/**
81
	 * @dataProvider invalidCoordinatesProvider
82
	 */
83
	public function testConstructorThrowsExceptionWhenParametersAreInvalid( float $latitude, float $longitude ) {
84
		$this->expectException( \InvalidArgumentException::class );
85
		new LatLongValue( $latitude, $longitude );
86
	}
87
88
	public function invalidCoordinatesProvider() {
89
		yield 'latitude too small' => [ -361, 0 ];
90
		yield 'latitude too big' => [ 361, 0 ];
91
		yield 'longitude too big' => [ 0, 361 ];
92
		yield 'longitude too small' => [ 0, -361 ];
93
	}
94
95
}
96