1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests; |
4
|
|
|
|
5
|
|
|
use SMW\Exception\DataItemException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers SMWDIGeoCoord |
9
|
|
|
* @covers SMWDataItem |
10
|
|
|
* |
11
|
|
|
* @author Jeroen De Dauw < [email protected] > |
12
|
|
|
*/ |
13
|
|
|
class SMWDIGeoCoordTest extends \PHPUnit_Framework_TestCase { |
14
|
|
|
|
15
|
|
|
public function testConstructorWithArrayArgumentForm() { |
16
|
|
|
$coordinate = new \SMWDIGeoCoord( [ 'lat' => 13.37, 'lon' => 42.42 ] ); |
17
|
|
|
|
18
|
|
|
$this->assertSame( 13.37, $coordinate->getLatitude() ); |
19
|
|
|
$this->assertSame( 42.42, $coordinate->getLongitude() ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testConstructorWithMultipleArgumentsForm() { |
23
|
|
|
$coordinate = new \SMWDIGeoCoord( 13.37, 42.42 ); |
24
|
|
|
|
25
|
|
|
$this->assertSame( 13.37, $coordinate->getLatitude() ); |
26
|
|
|
$this->assertSame( 42.42, $coordinate->getLongitude() ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testWhenConstructingWithIntegers_gettersReturnFloats() { |
30
|
|
|
$coordinate = new \SMWDIGeoCoord( 13, 42 ); |
31
|
|
|
|
32
|
|
|
$this->assertSame( 13.0, $coordinate->getLatitude() ); |
33
|
|
|
$this->assertSame( 42.0, $coordinate->getLongitude() ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testWhenOnlyProvidingLatitudeArgument_constructorThrowsException() { |
37
|
|
|
$this->setExpectedException( DataItemException::class ); |
38
|
|
|
new \SMWDIGeoCoord( 13 ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testWhenProvidingNonNumericalArgument_constructorThrowsException() { |
42
|
|
|
$this->setExpectedException( DataItemException::class ); |
43
|
|
|
new \SMWDIGeoCoord( 13, null ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testWhenProvidingArrayWithNonNumericalArgument_constructorThrowsException() { |
47
|
|
|
$this->setExpectedException( DataItemException::class ); |
48
|
|
|
new \SMWDIGeoCoord( [ 'lat' => null, 'lon' => 42.42 ] ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testObjectEqualsItself() { |
52
|
|
|
$coordinate = new \SMWDIGeoCoord( 13, 42 ); |
53
|
|
|
$this->assertTrue( $coordinate->equals( $coordinate ) ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testObjectEqualsDifferentInstancesWithEqualValues() { |
57
|
|
|
$coordinate = new \SMWDIGeoCoord( 13, 42 ); |
58
|
|
|
$this->assertTrue( $coordinate->equals( new \SMWDIGeoCoord( 13.0, 42.0 ) ) ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testObjectDoesNotEqualInstancesWithDifferentValues() { |
62
|
|
|
$coordinate = new \SMWDIGeoCoord( 13, 42 ); |
63
|
|
|
$this->assertFalse( $coordinate->equals( new \SMWDIGeoCoord( 1, 2 ) ) ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|