From df33d7edbc7d5367dc30c7e6cd92542aceaa3453 Mon Sep 17 00:00:00 2001 From: gridnev Date: Wed, 19 Feb 2020 12:17:36 +0300 Subject: [PATCH] Add Mail.ru service support --- src/Services/MailRu.php | 23 ++++++++++++++ src/TransparentEmailFactory.php | 2 ++ tests/Services/MailRuTest.php | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/Services/MailRu.php create mode 100644 tests/Services/MailRuTest.php diff --git a/src/Services/MailRu.php b/src/Services/MailRu.php new file mode 100644 index 0000000..26950ed --- /dev/null +++ b/src/Services/MailRu.php @@ -0,0 +1,23 @@ +removeSuffixAlias('+') + ->lowerCaseLocalPartIf(true); + } + + public function isSupported(EmailInterface $email) : bool + { + return in_array($email->getDomain(), ['mail.ru']); + } +} \ No newline at end of file diff --git a/src/TransparentEmailFactory.php b/src/TransparentEmailFactory.php index fff5cd7..8e6232c 100644 --- a/src/TransparentEmailFactory.php +++ b/src/TransparentEmailFactory.php @@ -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 ]; } } \ No newline at end of file diff --git a/tests/Services/MailRuTest.php b/tests/Services/MailRuTest.php new file mode 100644 index 0000000..13dd81c --- /dev/null +++ b/tests/Services/MailRuTest.php @@ -0,0 +1,53 @@ +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], + ]; + } +} \ No newline at end of file