Completed
Pull Request — master (#2)
by Daryl
02:44
created

TestGeocoder::testMakeRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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
 */
13
class TestGeocoder extends TestCase {
14
15
    /**
16
     * @var Geocoder;
17
     */
18
    private $_geocoder;
19
20
    public function setUp() {
21
        $this->_geocoder = new Geocoder(['api_key' => '']);
22
    }
23
24
    /**
25
     * @covers ::_make_request
26
     */
27
    public function testMakeRequest() {
28
        $url      = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_url', '1600 Amphitheatre Parkway, Mountain View, CA');
29
        $response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_request', $url);
30
31
        $this->assertInternalType('array', $response);
32
    }
33
34
    /**
35
     * @covers ::_make_request
36
     */
37
    public function testMakeRequestError404() {
38
        $response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_request', 'https://maps.googleapis.com/maps/api/geo');
39
40
        $this->assertInstanceOf('WP_Error', $response);
41
        $this->assertObjectHasAttribute('errors', $response);
42
        $this->assertArrayHasKey('404', $response->errors);
43
    }
44
45
    /**
46
     * @covers ::_get_data
47
     */
48
    public function testGetData() {
49
        $url      = $this->reflectionMethodInvokeArgs($this->_geocoder, '_make_url', '1600 Amphitheatre Parkway, Mountain View, CA');
50
        $response = $this->reflectionMethodInvokeArgs($this->_geocoder, '_get_data', $url);
51
52
        $this->assertInternalType('array', $response);
53
    }
54
55
    /**
56
     * @covers ::geocode
57
     */
58
    public function testGeocode() {
59
        $result = $this->_geocoder->geocode('1600 Amphitheatre Parkway, Mountain View, CA');
60
61
        $this->assertInternalType('array', $result);
62
        $this->assertArrayHasKey('lat', $result);
63
        $this->assertArrayHasKey('lng', $result);
64
    }
65
}
66