Add Mail.ru service support

This commit is contained in:
gridnev 2020-02-19 12:17:36 +03:00 committed by alexey11996
parent c83a423cd8
commit df33d7edbc
3 changed files with 78 additions and 0 deletions

23
src/Services/MailRu.php Normal file
View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Services;
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
class MailRu implements ServiceInterface
{
public function getPrimaryEmail(EmailInterface $email) : EmailInterface
{
return (new EditableEmail($email))
->removeSuffixAlias('+')
->lowerCaseLocalPartIf(true);
}
public function isSupported(EmailInterface $email) : bool
{
return in_array($email->getDomain(), ['mail.ru']);
}
}

View File

@ -6,6 +6,7 @@ namespace bkrukowski\TransparentEmail;
use bkrukowski\TransparentEmail\Services\AppsGoogleCom;
use bkrukowski\TransparentEmail\Services\GmailCom;
use bkrukowski\TransparentEmail\Services\MailRu;
use bkrukowski\TransparentEmail\Services\OutlookCom;
use bkrukowski\TransparentEmail\Services\TlenPl;
use bkrukowski\TransparentEmail\Services\Www33MailCom;
@ -38,6 +39,7 @@ class TransparentEmailFactory
Www33MailCom::class,
TlenPl::class,
AppsGoogleCom::class,
MailRu::class
];
}
}

View File

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace bkrukowski\TransparentEmail\Tests\Services;
use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\MailRu;
use PHPUnit\Framework\TestCase;
class MailRuTest extends TestCase
{
/**
* @dataProvider providerGetPrimaryEmail
*
* @param string $inputEmail
* @param string $outputEmail
*/
public function testGetPrimaryEmail(string $inputEmail, string $outputEmail)
{
$this->assertEquals($outputEmail, (new MailRu())->getPrimaryEmail(new Email($inputEmail)));
}
public function providerGetPrimaryEmail() : array
{
return [
['foobar@MAIL.RU', 'foobar@mail.ru'],
['fOObar@MaiL.Ru', 'foobar@mail.ru'],
['foobar+alias@mail.ru', 'foobar@mail.ru'],
];
}
/**
* @dataProvider providerIsSupported
*
* @param string $domain
* @param bool $result
*/
public function testIsSupported(string $domain, bool $result)
{
$this->assertSame($result, (new MailRu())->isSupported(new Email('Jane.Doe@' . $domain)));
}
public function providerIsSupported() : array
{
return [
['mail.ru', true],
['mail.RU', true],
['MAIL.RU', true],
['ma.il.ru', false],
];
}
}