-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathInsightsTest.php
More file actions
196 lines (165 loc) · 5.84 KB
/
Copy pathInsightsTest.php
File metadata and controls
196 lines (165 loc) · 5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
declare(strict_types=1);
namespace MaxMind\Test\MinFraud\Model;
use GeoIp2\Record\AnonymizerFeed;
use MaxMind\MinFraud\Model\Insights;
use MaxMind\MinFraud\Model\Score;
use MaxMind\Test\MinFraudData as Data;
/**
* @coversNothing
*
* @internal
*/
class InsightsTest extends ScoreTest
{
protected function response(): array
{
return Data::insightsFullResponse();
}
/**
* This is specified here as PHP 7.3 doesn't allow us to set it to
* Insights.
*/
protected function model(): Insights|Score
{
return new Insights($this->response(), ['fr']);
}
public function testInsightsProperties(): void
{
$array = $this->response();
$insights = $this->model();
// We test one field in each contained object to ensure that data
// is being passed correctly to these objects. There are specific
// tests of the objects themselves in the appropriately named classes.
$this->assertSame(
$array['ip_address']['country']['names']['fr'],
$insights->ipAddress->country->name,
'correct French country name'
);
$this->assertSame(
$array['ip_address']['risk_reasons'][0]['code'],
$insights->ipAddress->riskReasons[0]->code,
'correct IP risk reason code'
);
$this->assertTrue(
$insights->ipAddress->country->isInEuropeanUnion,
'country is in EU'
);
$this->assertFalse(
$insights->ipAddress->registeredCountry->isInEuropeanUnion,
'registered country is in EU'
);
$this->assertFalse(
$insights->ipAddress->representedCountry->isInEuropeanUnion,
'represented country is in EU'
);
$this->assertSame(
$array['credit_card']['issuer']['name'],
$insights->creditCard->issuer->name,
'correct CC issuer name'
);
$this->assertSame(
$array['shipping_address']['is_high_risk'],
$insights->shippingAddress->isHighRisk,
'correct shipping address risk'
);
$this->assertSame(
$array['billing_address']['latitude'],
$insights->billingAddress->latitude,
'correct billing latitude'
);
$this->assertTrue(
isset($insights->billingAddress->latitude),
'isset works for billing latitude'
);
$this->assertSame(
$array['email']['domain']['first_seen'],
$insights->email->domain->firstSeen,
'correct email domain first seen'
);
$this->assertFalse(
isset($insights->unknown),
'isset returns false for unknown method'
);
$this->assertNotEmpty(
$insights->billingAddress->latitude,
'empty works for billing latitude'
);
foreach (['isAnonymous',
'isAnonymousVpn',
'isHostingProvider',
'isPublicProxy',
'isTorExitNode',
] as $property) {
$this->assertTrue($insights->ipAddress->traits->{$property});
}
$this->assertSame(
$array['ip_address']['traits']['mobile_country_code'],
$insights->ipAddress->traits->mobileCountryCode,
'correct mobile country code'
);
$this->assertSame(
$array['ip_address']['traits']['mobile_network_code'],
$insights->ipAddress->traits->mobileNetworkCode,
'correct mobile network code'
);
// Test anonymizer object
foreach ([
'isAnonymous',
'isAnonymousVpn',
'isHostingProvider',
'isPublicProxy',
'isTorExitNode',
] as $property) {
$this->assertTrue(
$insights->ipAddress->anonymizer->{$property},
"anonymizer {$property} is true"
);
}
$this->assertSame(
$array['ip_address']['anonymizer']['confidence'],
$insights->ipAddress->anonymizer->confidence,
'correct anonymizer confidence'
);
$this->assertSame(
$array['ip_address']['anonymizer']['provider_name'],
$insights->ipAddress->anonymizer->providerName,
'correct anonymizer provider name'
);
$this->assertSame(
$array['ip_address']['anonymizer']['network_last_seen'],
$insights->ipAddress->anonymizer->networkLastSeen,
'correct anonymizer network last seen'
);
$this->assertInstanceOf(
AnonymizerFeed::class,
$insights->ipAddress->anonymizer->residential,
'anonymizer residential is an AnonymizerFeed'
);
$this->assertSame(
$array['ip_address']['anonymizer']['residential']['confidence'],
$insights->ipAddress->anonymizer->residential->confidence,
'correct anonymizer residential confidence'
);
$this->assertSame(
$array['ip_address']['anonymizer']['residential']['network_last_seen'],
$insights->ipAddress->anonymizer->residential->networkLastSeen,
'correct anonymizer residential network last seen'
);
$this->assertSame(
$array['ip_address']['anonymizer']['residential']['provider_name'],
$insights->ipAddress->anonymizer->residential->providerName,
'correct anonymizer residential provider name'
);
$this->assertSame(
$array['billing_phone']['country'],
$insights->billingPhone->country,
'correct billing phone country'
);
$this->assertSame(
$array['shipping_phone']['country'],
$insights->shippingPhone->country,
'correct shipping phone country'
);
}
}