PolygonTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidDataProvider() 0 35 1
A itShouldThrowInvalidPolygonException() 0 6 1
A itShouldWorksFine() 0 15 1
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