Completed
Pull Request — master (#22)
by Daryl
01:32
created

TestGeocoder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 69
rs 10
1
<?php
2
3
namespace Clubdeuce\WPLib\Components\GoogleMaps\Tests\Integration;
4
5
use Clubdeuce\WPLib\Components\GoogleMaps\Geocoder;
6
use Clubdeuce\WPLib\Components\GoogleMaps\Tests\TestCase;
7
8
/**
9
 * Class TestGeocoder
10
 * @package            Clubdeuce\WPLib\Components\GoogleMaps\Tests\Integration
11
 * @coversDefaultClass Clubdeuce\WPLib\Components\GoogleMaps\Geocoder
12
 * @group              geocoder
13
 */
14
class TestGeocoder extends TestCase {
15
16
    /**
17
     * @var Geocoder;
18
     */
19
    private $_geocoder;
20
21
    public function setUp() {
22
        $this->_geocoder = new Geocoder(array('api_key' => getenv('MAPS_API_KEY')));
23
	    parent::setUp();
24
    }
25
26
    /**
27
     * @covers ::geocode
28
     */
29
    public function testGeocode() {
30
        $location = $this->_geocoder->geocode('1600 Amphitheatre Parkway, Mountain View, CA');
31
32
        $this->assertInstanceOf('\Clubdeuce\WPLib\Components\GoogleMaps\Location', $location);
33
        $this->assertInternalType('string', $location->address());
34
        $this->assertInternalType('string', $location->formatted_address());
35
        $this->assertInternalType('double', $location->latitude());
36
        $this->assertInternalType('double', $location->longitude());
37
        $this->assertInternalType('array', $location->viewport());
38
        $this->assertArrayHasKey('northeast', $location->viewport());
39
        $this->assertArrayHasKey('southwest', $location->viewport());
40
        $this->assertInternalType('array', $location->viewport()['northeast']);
41
        $this->assertArrayHasKey('lat', $location->viewport()['northeast']);
42
        $this->assertArrayHasKey('lng', $location->viewport()['northeast']);
43
        $this->assertInternalType('double', $location->viewport()['northeast']['lat']);
44
        $this->assertInternalType('double', $location->viewport()['northeast']['lng']);
45
        $this->assertInternalType('array', $location->viewport()['southwest']);
46
        $this->assertArrayHasKey('lat', $location->viewport()['southwest']);
47
        $this->assertArrayHasKey('lng', $location->viewport()['southwest']);
48
        $this->assertInternalType('double', $location->viewport()['southwest']['lat']);
49
        $this->assertInternalType('double', $location->viewport()['southwest']['lng']);
50
    }
51
52
}
53