Completed
Push — master ( 1b0014...e530af )
by Tobias
03:11
created

GeoArrayTest::testDumpWithBounds()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Tests\Dumper;
14
15
use Geocoder\Dumper\GeoArray;
16
use Geocoder\Model\Address;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * @author Tomas Norkūnas <[email protected]>
21
 */
22
class GeoArrayTest extends TestCase
23
{
24
    /**
25
     * @var GeoArray
26
     */
27
    private $dumper;
28
29
    protected function setUp()
30
    {
31
        $this->dumper = new GeoArray();
32
    }
33
34
    public function testDump()
35
    {
36
        $address = Address::createFromArray([]);
37
        $expected = [
38
            'type' => 'Feature',
39
            'geometry' => [
40
                'type' => 'Point',
41
                'coordinates' => [0, 0],
42
            ],
43
            'properties' => [
44
                'providedBy' => 'n/a',
45
            ],
46
        ];
47
48
        $result = $this->dumper->dump($address);
49
50
        $this->assertInternalType('array', $result);
51
        $this->assertEquals($expected, $result);
52
    }
53
54
    public function testDumpWithData()
55
    {
56
        $address = Address::createFromArray([
57
            'latitude' => 48.8631507,
58
            'longitude' => 2.3889114,
59
        ]);
60
61
        $expected = [
62
            'type' => 'Feature',
63
            'geometry' => [
64
                'type' => 'Point',
65
                'coordinates' => [2.3889114, 48.8631507],
66
            ],
67
            'properties' => [
68
                'providedBy' => 'n/a',
69
            ],
70
        ];
71
72
        $result = $this->dumper->dump($address);
73
74
        $this->assertInternalType('array', $result);
75
        $this->assertEquals($expected, $result);
76
    }
77
78
    public function testDumpWithBounds()
79
    {
80
        $address = Address::createFromArray([
81
            'latitude' => 48.8631507,
82
            'longitude' => 2.3889114,
83
            'bounds' => [
84
                'south' => 48.8631507,
85
                'west' => 2.3889114,
86
                'north' => 48.8631507,
87
                'east' => 2.388911,
88
            ],
89
        ]);
90
91
        $expected = [
92
            'type' => 'Feature',
93
            'geometry' => [
94
                'type' => 'Point',
95
                'coordinates' => [2.3889114, 48.8631507],
96
            ],
97
            'properties' => [
98
                'providedBy' => 'n/a',
99
            ],
100
            'bounds' => [
101
                'south' => 48.8631507,
102
                'west' => 2.3889114,
103
                'north' => 48.8631507,
104
                'east' => 2.388911,
105
            ],
106
        ];
107
108
        $result = $this->dumper->dump($address);
109
110
        $this->assertInternalType('array', $result);
111
        $this->assertEquals($expected, $result);
112
    }
113
114
    public function testDumpWithProperties()
115
    {
116
        $address = Address::createFromArray([
117
            'latitude' => 48.8631507,
118
            'longitude' => 2.3889114,
119
            'bounds' => [
120
                'south' => 48.8631507,
121
                'west' => 2.3889114,
122
                'north' => 48.8631507,
123
                'east' => 2.388911,
124
            ],
125
            'locality' => 'Paris',
126
            'country' => 'France',
127
        ]);
128
129
        $expected = [
130
            'type' => 'Feature',
131
            'geometry' => [
132
                'type' => 'Point',
133
                'coordinates' => [2.3889114, 48.8631507],
134
            ],
135
            'properties' => [
136
                'locality' => 'Paris',
137
                'country' => 'France',
138
                'providedBy' => 'n/a',
139
            ],
140
            'bounds' => [
141
                'south' => 48.8631507,
142
                'west' => 2.3889114,
143
                'north' => 48.8631507,
144
                'east' => 2.388911,
145
            ],
146
        ];
147
148
        $result = $this->dumper->dump($address);
149
150
        $this->assertInternalType('array', $result);
151
        $this->assertEquals($expected, $result);
152
    }
153
}
154