1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpValueObjects\Tests\Spatial; |
6
|
|
|
|
7
|
|
|
use PhpValueObjects\Spatial\Exception\InvalidPolygonException; |
8
|
|
|
use PhpValueObjects\Tests\BaseUnitTestCase; |
9
|
|
|
|
10
|
|
|
final class PolygonTest extends BaseUnitTestCase |
11
|
|
|
{ |
12
|
|
|
public function invalidDataProvider(): array |
13
|
|
|
{ |
14
|
|
|
$latitude = $this->faker()->latitude; |
15
|
|
|
$longitude = $this->faker()->longitude; |
16
|
|
|
return [ |
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
|
|
|
* @test |
50
|
|
|
* @dataProvider invalidDataProvider |
51
|
|
|
*/ |
52
|
|
|
public function itShouldThrowInvalidPolygonException($values): void |
53
|
|
|
{ |
54
|
|
|
$this->expectException(InvalidPolygonException::class); |
55
|
|
|
|
56
|
|
|
new Polygon($values); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @test |
61
|
|
|
*/ |
62
|
|
|
public function itShouldWorksFine(): void |
63
|
|
|
{ |
64
|
|
|
$latitude = $this->faker()->latitude; |
65
|
|
|
$longitude = $this->faker()->longitude; |
66
|
|
|
|
67
|
|
|
$data = [ |
68
|
|
|
[$latitude, $longitude], |
69
|
|
|
[$this->faker()->latitude, $this->faker()->longitude], |
70
|
|
|
[$latitude, $longitude] |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
$polygon = new Polygon($data); |
74
|
|
|
|
75
|
|
|
$this->assertSame($data, $polygon->value()); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|