Update API Response model based on the API v4 documentation

This commit is contained in:
David Garcia 2019-08-09 23:57:04 +01:00
parent 281cb04130
commit 9cc5f4b3a7
No known key found for this signature in database
GPG Key ID: 5B833C2A14BD9A97
2 changed files with 36 additions and 84 deletions

View File

@ -23,11 +23,6 @@ final class ValidateResponse implements ApiResponse
*/ */
private $address; private $address;
/**
* @var string|null
*/
private $didYouMean;
/** /**
* @var bool * @var bool
*/ */
@ -39,24 +34,19 @@ final class ValidateResponse implements ApiResponse
private $isRoleAddress; private $isRoleAddress;
/** /**
* @var bool * @var string[]
*/ */
private $isValid; private $reason;
/**
* @var bool
*/
private $mailboxVerification;
/**
* @var Parts
*/
private $parts;
/** /**
* @var string|null * @var string|null
*/ */
private $reason; private $result;
/**
* @var string|null
*/
private $risk;
private function __construct() private function __construct()
{ {
@ -66,13 +56,11 @@ final class ValidateResponse implements ApiResponse
{ {
$model = new self(); $model = new self();
$model->address = $data['address'] ?? null; $model->address = $data['address'] ?? null;
$model->didYouMean = $data['did_you_mean'] ?? null;
$model->isDisposableAddress = $data['is_disposable_address'] ?? false; $model->isDisposableAddress = $data['is_disposable_address'] ?? false;
$model->isRoleAddress = $data['is_role_address'] ?? false; $model->isRoleAddress = $data['is_role_address'] ?? false;
$model->isValid = $data['is_valid'] ?? false; $model->reason = $data['reason'] ?? [];
$model->mailboxVerification = isset($data['mailbox_verification']) ? 'true' === $data['mailbox_verification'] : false; $model->result = $data['result'] ?? null;
$model->parts = Parts::create($data['parts'] ?? []); $model->risk = $data['risk'] ?? null;
$model->reason = $data['reason'] ?? null;
return $model; return $model;
} }
@ -82,11 +70,6 @@ final class ValidateResponse implements ApiResponse
return $this->address; return $this->address;
} }
public function getDidYouMean(): ?string
{
return $this->didYouMean;
}
public function isDisposableAddress(): bool public function isDisposableAddress(): bool
{ {
return $this->isDisposableAddress; return $this->isDisposableAddress;
@ -97,23 +80,24 @@ final class ValidateResponse implements ApiResponse
return $this->isRoleAddress; return $this->isRoleAddress;
} }
public function isValid(): bool public function getReason(): array
{
return $this->isValid;
}
public function isMailboxVerification(): bool
{
return $this->mailboxVerification;
}
public function getParts(): Parts
{
return $this->parts;
}
public function getReason(): ?string
{ {
return $this->reason; return $this->reason;
} }
/**
* @return string|null
*/
public function getResult(): ?string
{
return $this->result;
}
/**
* @return string|null
*/
public function getRisk(): ?string
{
return $this->risk;
}
} }

View File

@ -23,67 +23,35 @@ class ValidateResponseTest extends BaseModelTest
<<<'JSON' <<<'JSON'
{ {
"address": "foo@mailgun.net", "address": "foo@mailgun.net",
"did_you_mean": null,
"is_disposable_address": false, "is_disposable_address": false,
"is_role_address": true, "is_role_address": true,
"is_valid": true, "reason": [],
"mailbox_verification": "true", "result": "deliverable",
"parts": { "risk": "low"
"display_name": null,
"domain": "mailgun.net",
"local_part": "foo"
}
} }
JSON; JSON;
$model = ValidateResponse::create(json_decode($json, true)); $model = ValidateResponse::create(json_decode($json, true));
$this->assertTrue($model->isMailboxVerification()); $this->assertTrue($model->isMailboxVerification());
} }
public function testCreateWithoutMailboxVerification()
{
$json =
<<<'JSON'
{
"address": "foo@mailgun.net",
"did_you_mean": null,
"is_disposable_address": false,
"is_role_address": false,
"is_valid": true,
"mailbox_verification": null,
"parts": {
"display_name": null,
"domain": "mailgun.net",
"local_part": "foo"
},
"reason": null
}
JSON;
$model = ValidateResponse::create(json_decode($json, true));
$this->assertFalse($model->isMailboxVerification());
}
public function testEmailValidation() public function testEmailValidation()
{ {
$data = [ $data = [
'address' => 'foo@mailgun.net', 'address' => 'foo@mailgun.net',
'did_you_mean' => null,
'is_disposable_address' => false, 'is_disposable_address' => false,
'is_role_address' => false, 'is_role_address' => false,
'is_valid' => true, 'reason' => [],
'mailbox_verification' => null, 'result' => 'deliverable',
'parts' => ['display_name' => null, 'domain' => 'mailgun.net', 'local_part' => 'foo'], 'risk' => 'low'
'reason' => null,
]; ];
$parts = ValidateResponse::create($data); $parts = ValidateResponse::create($data);
$this->assertEquals($data['address'], $parts->getAddress()); $this->assertEquals($data['address'], $parts->getAddress());
$this->assertEquals($data['did_you_mean'], $parts->getDidYouMean());
$this->assertEquals($data['is_disposable_address'], $parts->isDisposableAddress()); $this->assertEquals($data['is_disposable_address'], $parts->isDisposableAddress());
$this->assertEquals($data['is_role_address'], $parts->isRoleAddress()); $this->assertEquals($data['is_role_address'], $parts->isRoleAddress());
$this->assertEquals($data['is_valid'], $parts->isValid());
$this->assertEquals($data['mailbox_verification'], $parts->isMailboxVerification());
$this->assertInstanceOf(Parts::class, $parts->getParts());
$this->assertEquals($data['reason'], $parts->getReason()); $this->assertEquals($data['reason'], $parts->getReason());
$this->assertEquals($data['result'], $parts->getResult());
$this->assertEquals($data['risk'], $parts->getRisk());
} }
} }