|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TraderInteractive\NetAcuity\Databases\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use TraderInteractive\NetAcuity\Databases\EdgeDatabase; |
|
6
|
|
|
use TraderInteractive\NetAcuity\Tests\NetAcuityTestSuite; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @coversDefaultClass \TraderInteractive\NetAcuity\Databases\AbstractNetAcuityDatabase |
|
11
|
|
|
* @covers ::__construct |
|
12
|
|
|
* @covers ::<protected> |
|
13
|
|
|
* @covers ::<private> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class AbstractNetAcuityDatabaseTest extends NetAcuityTestSuite |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @test |
|
19
|
|
|
* @covers ::fetch |
|
20
|
|
|
* |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
|
|
public function fetchUsingEdge() |
|
24
|
|
|
{ |
|
25
|
|
|
$mockResponse = $this->getMockResponse( |
|
26
|
|
|
[ |
|
27
|
|
|
'edge-country' => 'america/new_york', |
|
28
|
|
|
'edge-region' => 'usa', |
|
29
|
|
|
'edge-city' => 'radford', |
|
30
|
|
|
'edge-conn-speed' => 'broadband', |
|
31
|
|
|
'edge-metro-code' => '2', |
|
32
|
|
|
'edge-latitude' => '123.456', |
|
33
|
|
|
'edge-longitude' => '789.101', |
|
34
|
|
|
'edge-postal-code' => '24141', |
|
35
|
|
|
'edge-country-code' => '112', |
|
36
|
|
|
'edge-region-code' => '1314', |
|
37
|
|
|
'edge-city-code' => '1516', |
|
38
|
|
|
'edge-continent-code' => '1', |
|
39
|
|
|
'edge-two-letter-country' => 'US', |
|
40
|
|
|
'edge-area-codes' => '540', |
|
41
|
|
|
'edge-country-conf' => '30039', |
|
42
|
|
|
'edge-region-conf' => '33.9056', |
|
43
|
|
|
'edge-city-conf' => '99', |
|
44
|
|
|
'edge-postal-conf' => '99', |
|
45
|
|
|
'edge-gmt-offset' => '-500', |
|
46
|
|
|
'edge-in-dst' => 'n', |
|
47
|
|
|
'edge-timezone-name' => 't3', |
|
48
|
|
|
] |
|
49
|
|
|
); |
|
50
|
|
|
$mockClient = $this->getMockGuzzleClient(); |
|
51
|
|
|
$mockClient->method('send')->willReturn($mockResponse); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$database = new EdgeDatabase($mockClient, 'a token'); |
|
54
|
|
|
$actual = $database->fetch('192.168.1.1'); |
|
55
|
|
|
|
|
56
|
|
|
$expected = [ |
|
57
|
|
|
'area-code' => '540', |
|
58
|
|
|
'city' => 'radford', |
|
59
|
|
|
'city-code' => '1516', |
|
60
|
|
|
'city-conf' => '99', |
|
61
|
|
|
'conn-speed' => 'broadband', |
|
62
|
|
|
'continent-code' => '1', |
|
63
|
|
|
'country' => 'america/new_york', |
|
64
|
|
|
'country-code' => '112', |
|
65
|
|
|
'country-conf' => '30039', |
|
66
|
|
|
'gmt-offset' => '-500', |
|
67
|
|
|
'in-dist' => 'n', |
|
68
|
|
|
'latitude' => '123.456', |
|
69
|
|
|
'longitude' => '789.101', |
|
70
|
|
|
'metro-code' => '2', |
|
71
|
|
|
'postal-conf' => '99', |
|
72
|
|
|
'region' => 'usa', |
|
73
|
|
|
'region-code' => '1314', |
|
74
|
|
|
'region-conf' => '33.9056', |
|
75
|
|
|
'timezone-name' => 't3', |
|
76
|
|
|
'two-letter-country' => 'US', |
|
77
|
|
|
'zip-code' => '24141', |
|
78
|
|
|
]; |
|
79
|
|
|
|
|
80
|
|
|
$this->assertSame($expected, $actual); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* |
|
85
|
|
|
* @test |
|
86
|
|
|
* @covers ::fetch |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getGeoWithExtraFieldEdge() |
|
89
|
|
|
{ |
|
90
|
|
|
$mockResponse = $this->getMockResponse( |
|
91
|
|
|
[ |
|
92
|
|
|
'edge-country' => 'USA', |
|
93
|
|
|
'edge-region' => 'something', |
|
94
|
|
|
'edge-city' => 'reserved', |
|
95
|
|
|
'edge-conn-speed' => 'broadband', |
|
96
|
|
|
'edge-metro-code' => '2', |
|
97
|
|
|
'edge-latitude' => '123.456', |
|
98
|
|
|
'edge-longitude' => '789.101', |
|
99
|
|
|
'edge-postal-code' => '12345', |
|
100
|
|
|
'edge-country-code' => '112', |
|
101
|
|
|
'edge-region-code' => '1314', |
|
102
|
|
|
'edge-city-code' => '1516', |
|
103
|
|
|
'edge-continent-code' => '1', |
|
104
|
|
|
'edge-two-letter-country' => 'US', |
|
105
|
|
|
'edge-area-codes' => '123', |
|
106
|
|
|
'edge-country-conf' => '2', |
|
107
|
|
|
'edge-region-conf' => '3', |
|
108
|
|
|
'edge-city-conf' => '4', |
|
109
|
|
|
'edge-postal-conf' => '5', |
|
110
|
|
|
'edge-gmt-offset' => '6', |
|
111
|
|
|
'edge-in-dst' => '7', |
|
112
|
|
|
'edge-timezone-name' => 'UTC', |
|
113
|
|
|
'edge-extra' => 'erroneous', |
|
114
|
|
|
] |
|
115
|
|
|
); |
|
116
|
|
|
$mockClient = $this->getMockGuzzleClient(); |
|
117
|
|
|
$mockClient->method('send')->willReturn($mockResponse); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
$database = new EdgeDatabase($mockClient, 'a token'); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertSame( |
|
122
|
|
|
[ |
|
123
|
|
|
'area-code' => '123', |
|
124
|
|
|
'city' => 'reserved', |
|
125
|
|
|
'city-code' => '1516', |
|
126
|
|
|
'city-conf' => '4', |
|
127
|
|
|
'conn-speed' => 'broadband', |
|
128
|
|
|
'continent-code' => '1', |
|
129
|
|
|
'country' => 'USA', |
|
130
|
|
|
'country-code' => '112', |
|
131
|
|
|
'country-conf' => '2', |
|
132
|
|
|
'gmt-offset' => '6', |
|
133
|
|
|
'in-dist' => '7', |
|
134
|
|
|
'latitude' => '123.456', |
|
135
|
|
|
'longitude' => '789.101', |
|
136
|
|
|
'metro-code' => '2', |
|
137
|
|
|
'postal-conf' => '5', |
|
138
|
|
|
'region' => 'something', |
|
139
|
|
|
'region-code' => '1314', |
|
140
|
|
|
'region-conf' => '3', |
|
141
|
|
|
'timezone-name' => 'UTC', |
|
142
|
|
|
'two-letter-country' => 'US', |
|
143
|
|
|
'zip-code' => '12345', |
|
144
|
|
|
], |
|
145
|
|
|
$database->fetch('1.2.3.4') |
|
146
|
|
|
); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Verify that ip address must be a string. |
|
151
|
|
|
* |
|
152
|
|
|
* @test |
|
153
|
|
|
* @covers ::fetch |
|
154
|
|
|
* @expectedException Exception |
|
155
|
|
|
* @expectedExceptionMessage NetAcuity API rejected the request, Reason: Invalid IP (1) |
|
156
|
|
|
* @expectedExceptionCode 400 |
|
157
|
|
|
*/ |
|
158
|
|
View Code Duplication |
public function getGeoNonStringIp() |
|
|
|
|
|
|
159
|
|
|
{ |
|
160
|
|
|
$mockException = $this->getMockClientException(400, 'Invalid IP (1)'); |
|
161
|
|
|
$mockClient = $this->getMockGuzzleClient(); |
|
162
|
|
|
$mockClient->method('send')->will($this->throwException($mockException)); |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
$database = new EdgeDatabase($mockClient, 'a token'); |
|
165
|
|
|
$database->fetch(1); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @test |
|
170
|
|
|
* |
|
171
|
|
|
* @covers ::fetch |
|
172
|
|
|
* |
|
173
|
|
|
* @expectedException Exception |
|
174
|
|
|
* @expectedExceptionMessage NetAcuity API rejected the provided api user token. |
|
175
|
|
|
* @expectedExceptionCode 403 |
|
176
|
|
|
*/ |
|
177
|
|
View Code Duplication |
public function netAcuityUserTokenInvalid() |
|
|
|
|
|
|
178
|
|
|
{ |
|
179
|
|
|
$mockException = $this->getMockClientException(403, 'Invalid IP (1)'); |
|
180
|
|
|
$mockClient = $this->getMockGuzzleClient(); |
|
181
|
|
|
$mockClient->method('send')->will($this->throwException($mockException)); |
|
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
$database = new EdgeDatabase($mockClient, 'a token'); |
|
184
|
|
|
$database->fetch('127.0.0.1'); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.