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
|
|
|
|
2019-01-12 12:09:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Mailgun
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
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;
|
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()
|
|
|
|
{
|
|
|
|
$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()
|
|
|
|
{
|
|
|
|
$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());
|
|
|
|
}
|
|
|
|
}
|