Skip to content

Commit 3328a45

Browse files
author
Dominik Hošic
committed
Email resource - added support for entire query as input parameter
1 parent ea3dc26 commit 3328a45

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/Resources/Email.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ final class Email extends BaseResource
1414
/**
1515
* Validate an email address.
1616
*
17-
* @param string $email Email address to validate
17+
* @param string|array $query Email address to validate
1818
*
1919
* @return Response The response from the validation request
2020
*/
21-
public function validate($email): Response
21+
public function validate($query): Response
2222
{
23-
$query = ["email" => $email];
23+
$query = is_array($query) ? $query : ["email" => $query];
2424
return $this->sendRequest($query);
2525
}
2626

2727
/**
2828
* Search for information related to an email address.
2929
*
30-
* @param string $email Email address to search for
30+
* @param string|array $query Email address to search for
3131
*
3232
* @return Response The response from the search request
3333
*/
34-
public function search(string $email): Response
34+
public function search($query): Response
3535
{
36-
$query = ["value" => $email];
36+
$query = is_array($query) ? $query : ["value" => $query];
3737
return $this->sendRequest($query);
3838
}
3939

tests/Unit/Email/EmailSearchTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function testSearchResults()
2020
// Input string for email search.
2121
$input = 'info@';
2222

23+
// Options that will be sent within the request.
2324
$options = [
2425
"resultsLimit" => 5
2526
];
@@ -35,4 +36,27 @@ public function testSearchResults()
3536
$this->assertGreaterThan(0, $response->getResponse()->resultsCount);
3637
$this->assertNotEmpty($result);
3738
}
39+
40+
/**
41+
* Test email search when the input parameter is specified as the entire query.
42+
*/
43+
public function testQueryInput()
44+
{
45+
// Query that will be sent to the API for validation.
46+
$query = [
47+
"value" => "info@"
48+
];
49+
50+
// Options that will be sent within the request.
51+
$options = [
52+
"resultsLimit" => 5
53+
];
54+
55+
// Perform email validation.
56+
$response = $this->api->email->setOptions($options)->search($query);
57+
58+
// Assertions.
59+
$this->assertInstanceOf(Response::class, $response);
60+
$this->assertEquals(200, $response->getStatus());
61+
}
3862
}

tests/Unit/Email/EmailValidateTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,27 @@ public function testWithClient()
233233
$this->assertEquals(200, $response->getStatus());
234234
$this->assertTrue($result->isValid);
235235
}
236+
237+
/**
238+
* Test email validation when the input parameter is specified as the entire query.
239+
*/
240+
public function testQueryInput()
241+
{
242+
// Query that will be sent to the API for validation.
243+
$query = [
244+
"email" => "[email protected]"
245+
];
246+
247+
// Options that will be sent within the request.
248+
$options = [
249+
"validationType" => "extended"
250+
];
251+
252+
// Perform email validation.
253+
$response = $this->api->email->setOptions($options)->validate($query);
254+
255+
// Assertions.
256+
$this->assertInstanceOf(Response::class, $response);
257+
$this->assertEquals(200, $response->getStatus());
258+
}
236259
}

0 commit comments

Comments
 (0)