1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpValueObjects\Tests\Spatial; |
4
|
|
|
|
5
|
|
|
use PhpValueObjects\Spatial\Exception\InvalidPolygonException; |
6
|
|
|
use PhpValueObjects\Tests\BaseUnitTestCase; |
7
|
|
|
|
8
|
|
|
class PolygonValueObjectTest extends BaseUnitTestCase |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
public function invalidDataProvider() |
12
|
|
|
{ |
13
|
|
|
$latitude = $this->faker()->latitude; |
14
|
|
|
$longitude = $this->faker()->longitude; |
15
|
|
|
return [ |
16
|
|
|
['no_array' => 'string'], |
17
|
|
|
[ |
18
|
|
|
'no_two_elements_by_array' => [ |
19
|
|
|
[$this->faker()->latitude], |
20
|
|
|
[$this->faker()->lastName, $this->faker()->longitude], |
21
|
|
|
[$this->faker()->lastName, $this->faker()->longitude] |
22
|
|
|
] |
23
|
|
|
], |
24
|
|
|
[ |
25
|
|
|
'no_same_start_end_data' => [ |
26
|
|
|
[$this->faker()->latitude, $this->faker()->longitude], |
27
|
|
|
[$this->faker()->latitude, $this->faker()->longitude], |
28
|
|
|
[$this->faker()->latitude, $this->faker()->randomFloat()], |
29
|
|
|
] |
30
|
|
|
], |
31
|
|
|
[ |
32
|
|
|
'no_polygon' => [ |
33
|
|
|
[$latitude, $longitude], |
34
|
|
|
[$latitude, $longitude], |
35
|
|
|
] |
36
|
|
|
], |
37
|
|
|
[ |
38
|
|
|
'element_no_array' => [ |
39
|
|
|
[$latitude, $longitude], |
40
|
|
|
'string', |
41
|
|
|
[$this->faker()->lastName, $this->faker()->longitude], |
42
|
|
|
[$latitude, $longitude] |
43
|
|
|
] |
44
|
|
|
] |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $values |
50
|
|
|
* @test |
51
|
|
|
* @dataProvider invalidDataProvider |
52
|
|
|
*/ |
53
|
|
|
public function itShouldThrowInvalidPolygonException($values) |
54
|
|
|
{ |
55
|
|
|
$this->expectException(InvalidPolygonException::class); |
56
|
|
|
|
57
|
|
|
new PolygonValueObject($values); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @test |
62
|
|
|
*/ |
63
|
|
|
public function itShouldWorksFine() |
64
|
|
|
{ |
65
|
|
|
$latitude = $this->faker()->latitude; |
66
|
|
|
$longitude = $this->faker()->longitude; |
67
|
|
|
|
68
|
|
|
$data = [ |
69
|
|
|
[$latitude, $longitude], |
70
|
|
|
[$this->faker()->latitude, $this->faker()->longitude], |
71
|
|
|
[$latitude, $longitude] |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
$polygon = new PolygonValueObject($data); |
75
|
|
|
|
76
|
|
|
$this->assertSame($data, $polygon->value()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|