Completed
Pull Request — master (#156)
by Jeroen De
04:20 queued 02:08
created

LatLongValueTest::testGetHashProducesMd5()   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 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Tests\DataValues\Geo\Values;
6
7
use DataValues\Geo\Values\LatLongValue;
8
9
/**
10
 * @covers \DataValues\Geo\Values\LatLongValue
11
 *
12
 * @group DataValue
13
 * @group DataValueExtensions
14
 *
15
 * @license GPL-2.0-or-later
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class LatLongValueTest extends DataValueTest {
19
20
	/**
21
	 * @see DataValueTest::getClass
22
	 *
23
	 * @return string
24
	 */
25
	public function getClass() {
26
		return LatLongValue::class;
27
	}
28
29
	public function validConstructorArgumentsProvider() {
30
		$argLists = [];
31
32
		$argLists[] = [ 4.2, 4.2 ];
33
		$argLists[] = [ 4.2, 42 ];
34
		$argLists[] = [ 42, 4.2 ];
35
		$argLists[] = [ 42, 42 ];
36
		$argLists[] = [ -4.2, -4.2 ];
37
		$argLists[] = [ 4.2, -42 ];
38
		$argLists[] = [ -42, 4.2 ];
39
		$argLists[] = [ 360, -360 ];
40
		$argLists[] = [ 48.269, -225.99 ];
41
		$argLists[] = [ 0, 0 ];
42
43
		return $argLists;
44
	}
45
46
	public function invalidConstructorArgumentsProvider() {
47
		$argLists = [];
48
49
		$argLists[] = [ -361, 0 ];
50
		$argLists[] = [ -999, 1 ];
51
		$argLists[] = [ 360.001, 2 ];
52
		$argLists[] = [ 3, 361 ];
53
		$argLists[] = [ 4, -1337 ];
54
55
		return $argLists;
56
	}
57
58
	/**
59
	 * @dataProvider instanceProvider
60
	 * @param LatLongValue $latLongValue
61
	 * @param array $arguments
62
	 */
63
	public function testGetLatitude( LatLongValue $latLongValue, array $arguments ) {
64
		$actual = $latLongValue->getLatitude();
65
66
		$this->assertInternalType( 'float', $actual );
67
		$this->assertSame( (float)$arguments[0], $actual );
68
	}
69
70
	/**
71
	 * @dataProvider instanceProvider
72
	 * @param LatLongValue $latLongValue
73
	 * @param array $arguments
74
	 */
75
	public function testGetLongitude( LatLongValue $latLongValue, array $arguments ) {
76
		$actual = $latLongValue->getLongitude();
77
78
		$this->assertInternalType( 'float', $actual );
79
		$this->assertSame( (float)$arguments[1], $actual );
80
	}
81
82
	/**
83
	 * @dataProvider invalidCoordinatesProvider
84
	 */
85
	public function testConstructorThrowsExceptionWhenParametersAreInvalid( float $latitude, float $longitude ) {
86
		$this->expectException( \InvalidArgumentException::class );
87
		new LatLongValue( $latitude, $longitude );
88
	}
89
90
	public function invalidCoordinatesProvider() {
91
		yield 'latitude too small' => [ -361, 0 ];
92
		yield 'latitude too big' => [ 361, 0 ];
93
		yield 'longitude too big' => [ 0, 361 ];
94
		yield 'longitude too small' => [ 0, -361 ];
95
	}
96
97
	public function testCopyProducesIdenticalObject() {
98
		$latLong = new LatLongValue( 1, 2 );
99
		$this->assertEquals(
100
			$latLong,
101
			$latLong->getCopy()
102
		);
103
	}
104
105
	public function testCopyProducesObjectWithDifferentIdentity() {
106
		$latLong = new LatLongValue( 1, 2 );
107
		$this->assertNotSame(
108
			$latLong,
109
			$latLong->getCopy()
110
		);
111
	}
112
113
	public function testGetHashProducesMd5() {
114
		$this->assertSame( '7a6ba7398547fbc6bc26fb3d77b93897', ( new LatLongValue( 0, 0 ) )->getHash() );
115
		$this->assertSame( 'b8af9bef608c55ae8c1610daa89e937f', ( new LatLongValue( 1, 2 ) )->getHash() );
116
	}
117
118
	/**
119
	 * @dataProvider instanceProvider
120
	 */
121
	public function testValuesEqualThemselves( LatLongValue $latLongValue ) {
122
		$this->assertTrue( $latLongValue->equals( $latLongValue ) );
123
	}
124
125
	/**
126
	 * @dataProvider instanceProvider
127
	 */
128
	public function testIdenticalValuesAreEqual( LatLongValue $latLongValue ) {
129
		$this->assertTrue( $latLongValue->equals( $latLongValue->getCopy() ) );
130
	}
131
132
	public function testDifferentValuesDoNotEqual() {
133
		$this->assertFalse(
134
			( new LatLongValue( 0, 0 ) )->equals( new LatLongValue( 1, 0 ) )
135
		);
136
137
		$this->assertFalse(
138
			( new LatLongValue( 0, 0 ) )->equals( new LatLongValue( 0, 1 ) )
139
		);
140
141
		$this->assertFalse(
142
			( new LatLongValue( 0, 0 ) )->equals( new LatLongValue( 0, 0.01 ) )
143
		);
144
145
		$this->assertFalse(
146
			( new LatLongValue( 0, 1 ) )->equals( new LatLongValue( 0, -1 ) )
147
		);
148
	}
149
150
}
151