Skip to content

Commit 929193f

Browse files
committed
MinFraud now implements JsonSerializable
1 parent 47a1d34 commit 929193f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

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 & 0 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
*/

0 commit comments

Comments
 (0)