-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace bkrukowski\TransparentEmail\Services; | ||
|
||
use bkrukowski\TransparentEmail\Emails\EditableEmail; | ||
use bkrukowski\TransparentEmail\Emails\EmailInterface; | ||
|
||
class YandexRu implements ServiceInterface | ||
{ | ||
public function getPrimaryEmail(EmailInterface $email) : EmailInterface | ||
{ | ||
return (new EditableEmail($email)) | ||
->removeSuffixAlias('+') | ||
->lowerCaseLocalPartIf(true) | ||
->setDomain($this->mapDomain($email->getDomain())); | ||
} | ||
|
||
public function isSupported(EmailInterface $email) : bool | ||
{ | ||
return in_array($email->getDomain(), ['ya.ru', 'yandex.ru']); | ||
} | ||
|
||
protected function getDomainMapping() : array | ||
{ | ||
return [ | ||
'ya.ru' => 'yandex.ru', | ||
]; | ||
} | ||
|
||
private function mapDomain(string $domain) : string | ||
{ | ||
return $this->getDomainMapping()[$domain] ?? $domain; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace bkrukowski\TransparentEmail\Tests\Services; | ||
|
||
use bkrukowski\TransparentEmail\Emails\Email; | ||
use bkrukowski\TransparentEmail\Services\YandexRu; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class YandexRuTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider providerGetPrimaryEmail | ||
* | ||
* @param string $inputEmail | ||
* @param string $outputEmail | ||
*/ | ||
public function testGetPrimaryEmail(string $inputEmail, string $outputEmail) | ||
{ | ||
$this->assertEquals($outputEmail, (new YandexRu())->getPrimaryEmail(new Email($inputEmail))); | ||
} | ||
|
||
public function providerGetPrimaryEmail() : array | ||
{ | ||
return [ | ||
['foobar@YANDEX.RU', 'foobar@yandex.ru'], | ||
['fOObar@YAndEX.ru', 'foobar@yandex.ru'], | ||
['foobar+alias@yandex.ru', 'foobar@yandex.ru'], | ||
['JaneDoe@ya.ru', 'janedoe@yandex.ru'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providerIsSupported | ||
* | ||
* @param string $domain | ||
* @param bool $result | ||
*/ | ||
public function testIsSupported(string $domain, bool $result) | ||
{ | ||
$this->assertSame($result, (new YandexRu())->isSupported(new Email('Jane.Doe@' . $domain))); | ||
} | ||
|
||
public function providerIsSupported() : array | ||
{ | ||
return [ | ||
['yandex.ru', true], | ||
['yandex.RU', true], | ||
['yan.dex.ru', false], | ||
['YANDEX.RU', true], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.