Skip to content

Commit 5318511

Browse files
authored
Merge pull request #193 from noefleury/feat/minfraud-json-serializable
MinFraud now implements JsonSerializable
2 parents 47a1d34 + 3ed1dce commit 5318511

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/MinFraud.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* If the request fails, an exception is thrown.
4141
*/
42-
class MinFraud extends MinFraud\ServiceClient
42+
class MinFraud extends MinFraud\ServiceClient implements \JsonSerializable
4343
{
4444
/**
4545
* @var array<string, mixed>
@@ -98,6 +98,18 @@ public function __construct(
9898
parent::__construct($accountId, $licenseKey, $options);
9999
}
100100

101+
/**
102+
* @return array<string, mixed>
103+
*/
104+
public function jsonSerialize(): array
105+
{
106+
return [
107+
'content' => $this->content ?? [],
108+
'hashEmail' => $this->hashEmail,
109+
'locales' => $this->locales,
110+
];
111+
}
112+
101113
/**
102114
* This returns a `MinFraud` object with the array to be sent to the web
103115
* service set to `$values`. Existing values will be replaced.

tests/MaxMind/Test/MinFraudTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616
*/
1717
class MinFraudTest extends ServiceClientTester
1818
{
19+
public function testMinFraud(): void
20+
{
21+
$minFraud = new MinFraud(0, '', ['hashEmail' => true, 'locales' => ['en', 'fr']]);
22+
$minFraud = $minFraud->withDevice(['ip_address' => '1.2.3.4']);
23+
24+
$array = [
25+
'content' => ['device' => ['ip_address' => '1.2.3.4']],
26+
'hashEmail' => true,
27+
'locales' => ['en', 'fr'],
28+
];
29+
30+
$this->assertSame(
31+
$array,
32+
$minFraud->jsonSerialize(),
33+
'correctly implements JsonSerializable'
34+
);
35+
}
36+
1937
/**
2038
* @dataProvider services
2139
*/
@@ -195,7 +213,6 @@ public function testEmailHashingDisabled(): void
195213
// Reflection isn't ideal, but this is the easiest way to check.
196214
$class = new \ReflectionClass(MinFraud::class);
197215
$prop = $class->getProperty('content');
198-
$prop->setAccessible(true);
199216

200217
$client = $this->createMinFraudRequestWithFullResponse(
201218
'insights',
@@ -234,7 +251,6 @@ public function testEmailHashingEnabled(): void
234251
// Reflection isn't ideal, but this is the easiest way to check.
235252
$class = new \ReflectionClass(MinFraud::class);
236253
$prop = $class->getProperty('content');
237-
$prop->setAccessible(true);
238254

239255
$client = $this->createMinFraudRequestWithFullResponse(
240256
'insights',

0 commit comments

Comments
 (0)