2018-02-02 02:51:47 +03:00
|
|
|
<?php
|
|
|
|
|
2019-01-12 11:54:00 +03:00
|
|
|
declare(strict_types=1);
|
2018-02-02 02:54:22 +03:00
|
|
|
|
2018-02-02 02:51:47 +03:00
|
|
|
namespace Mailgun\Tests\Model\EmailValidation;
|
|
|
|
|
2019-01-12 11:54:00 +03:00
|
|
|
use Mailgun\Model\EmailValidation\ParseResponse;
|
|
|
|
use Mailgun\Model\EmailValidation\ValidateResponse;
|
2019-01-10 00:40:29 +03:00
|
|
|
use Mailgun\Tests\Model\BaseModelTest;
|
2018-02-02 02:51:47 +03:00
|
|
|
|
2019-01-12 11:54:00 +03:00
|
|
|
class ParseResponseTest extends BaseModelTest
|
2018-02-02 02:51:47 +03:00
|
|
|
{
|
2019-01-12 11:54:00 +03:00
|
|
|
public function testCreate()
|
|
|
|
{
|
|
|
|
$json =
|
|
|
|
<<<'JSON'
|
|
|
|
{
|
|
|
|
"parsed": [
|
|
|
|
"Alice <alice@example.com>",
|
|
|
|
"bob@example.com"
|
|
|
|
],
|
|
|
|
"unparseable": [
|
|
|
|
]
|
|
|
|
}
|
|
|
|
JSON;
|
|
|
|
$model = ParseResponse::create(json_decode($json, true));
|
|
|
|
$this->assertNotEmpty($model->getParsed());
|
|
|
|
$this->assertCount(2, $model->getParsed());
|
|
|
|
$this->assertEmpty($model->getUnparseable());
|
|
|
|
}
|
|
|
|
|
2018-02-02 02:51:47 +03:00
|
|
|
public function testParseConstructorWithValidData()
|
|
|
|
{
|
2019-01-10 00:40:29 +03:00
|
|
|
|
2018-02-02 02:51:47 +03:00
|
|
|
$data = [
|
|
|
|
'parsed' => ['parsed data'],
|
|
|
|
'unparseable' => ['unparseable data'],
|
|
|
|
];
|
|
|
|
|
2019-01-12 11:54:00 +03:00
|
|
|
$parts = ParseResponse::create($data);
|
2018-02-02 02:51:47 +03:00
|
|
|
|
|
|
|
$this->assertEquals($data['parsed'], $parts->getParsed());
|
|
|
|
$this->assertEquals($data['unparseable'], $parts->getUnparseable());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testParseConstructorWithInvalidData()
|
|
|
|
{
|
2019-01-10 00:40:29 +03:00
|
|
|
|
2018-02-02 02:51:47 +03:00
|
|
|
$data = [
|
|
|
|
'parsed' => null,
|
|
|
|
'unparseable' => null,
|
|
|
|
];
|
|
|
|
|
2019-01-12 11:54:00 +03:00
|
|
|
$parts = ParseResponse::create($data);
|
2018-02-02 02:51:47 +03:00
|
|
|
|
|
|
|
$this->assertEquals([], $parts->getParsed());
|
|
|
|
$this->assertEquals([], $parts->getUnparseable());
|
|
|
|
}
|
2019-01-12 11:54:00 +03:00
|
|
|
|
2018-02-02 02:51:47 +03:00
|
|
|
}
|