Skip to content

Commit

Permalink
Merge afbd339 into ba89a9b
Browse files Browse the repository at this point in the history
  • Loading branch information
gridnevalex committed Feb 13, 2020
2 parents ba89a9b + afbd339 commit 30825ed
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ install:
- mkdir -p build/logs

php:
- 7.0
- 7.1
- nightly
- 7.2
- 7.3
- 7.4

script:
- ./vendor/bin/phpunit
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ To detect multi-accounts on your website.
* [33mail.com](https://www.33mail.com)
* [outlook.com](http://outlook.com)
* [yahoo.com](http://mail.yahoo.com)
* [yandex.ru](https://yandex.ru/)
* [mail.ru](https://mail.ru/)

## Usage

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "bkrukowski/transparent-email",
"name": "gridnevalex/transparent-email",
"description": "Remove aliases from email and get primary email account",
"type": "library",
"require": {
"php": "^7.0.0"
},
"require-dev": {
"phpunit/phpunit": "^5.5.4",
"phpunit/phpunit": "^8.5.2",
"satooshi/php-coveralls": "^1.0.1",
"codacy/coverage": "^1.0.3"
},
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.5/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="auto"
colors="true"
>

<testsuites>
Expand Down
23 changes: 23 additions & 0 deletions src/Services/MailRU.php
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']);
}
}
36 changes: 36 additions & 0 deletions src/Services/YandexRu.php
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;
}
}
15 changes: 13 additions & 2 deletions tests/Emails/EditableEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use bkrukowski\TransparentEmail\Emails\EditableEmail;
use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
use PHPUnit\Framework\TestCase;

class EditableEmailTest extends \PHPUnit_Framework_TestCase
class EditableEmailTest extends TestCase
{
/**
* @dataProvider providerRemoveFromLocalPart
Expand All @@ -19,7 +20,7 @@ public function testRemoveFromLocalPart(EmailInterface $email, string $toRemove)
$editable = new EditableEmail($email);
$new = $editable->removeFromLocalPart($toRemove);
$this->assertNotSame($editable, $new);
$this->assertNotContains((string) $new, $toRemove);
$this->assertStringNotContainsString((string) $new, $toRemove);
$this->assertSame($email->getDomain(), $new->getDomain());
}

Expand All @@ -28,6 +29,8 @@ public function providerRemoveFromLocalPart() : array
return [
[new Email('jane.doe.1990@gmail.com'), '.'],
[new Email('janedoe1990@gmail.com'), '.'],
[new Email('jane.doe.1990@yandex.ru'), '.'],
[new Email('janedoe1990@yandex.ru'), '.'],
];
}

Expand All @@ -53,6 +56,8 @@ public function providerRemoveSuffixAlias() : array
[new Email('John.Doe+alias@gmail.com', true), '+', 'John.Doe@gmail.com'],
[new Email('JohnDoe-alias@gmail.com'), '-', 'johndoe@gmail.com'],
[new Email('JohnDoe@gmail.com'), '-', 'johndoe@gmail.com'],
[new Email('JohnDoe+alias@yandex.ru'), '+', 'johndoe@yandex.ru'],
[new Email('JohnDoe+alias@mail.ru'), '+', 'johndoe@mail.ru'],
];
}

Expand All @@ -77,6 +82,10 @@ public function providerSetDomain() : array
[new Email('jane.doe@foo.bar'), 'gmail.com'],
[new Email('jane.doe@foo.bar'), 'foo.bar'],
[new Email('jane.doe@gmail.com'), 'foo.bar'],
[new Email('jane.doe@yandex.ru'), 'yandex.ru'],
[new Email('jane.doe@mail.ru'), 'mail.ru'],
[new Email('jane.doe@yandex.ru'), 'foo.bar'],
[new Email('jane.doe@mail.ru'), 'foo.bar'],
];
}

Expand All @@ -101,6 +110,8 @@ public function providerSetLocalPart() : array
[new Email('jane.doe@foo.bar'), 'jane'],
[new Email('jane.doe@foo.bar'), 'john'],
[new Email('jane.doe@gmail.com'), 'jane.doe'],
[new Email('jane.doe@yandex.ru'), 'jane.doe'],
[new Email('jane.doe@mail.ru'), 'jane.doe'],
];
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Emails/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Emails\InvalidEmailException;
use PHPUnit\Framework\TestCase;

class EmailTest extends \PHPUnit_Framework_TestCase
class EmailTest extends TestCase
{
/**
* @dataProvider providerConstructor
Expand Down
3 changes: 2 additions & 1 deletion tests/ServiceCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\ServiceCollector;
use bkrukowski\TransparentEmail\Services\ServiceInterface;
use PHPUnit\Framework\TestCase;

class ServiceCollectorTest extends \PHPUnit_Framework_TestCase
class ServiceCollectorTest extends TestCase
{
public function testAddService()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/AppsGoogleComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\AppsGoogleCom;
use PHPUnit\Framework\TestCase;

class AppsGoogleComTest extends \PHPUnit_Framework_TestCase
class AppsGoogleComTest extends TestCase
{
/**
* @dataProvider providerIsSupported
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/GmailComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\GmailCom;
use PHPUnit\Framework\TestCase;

class GmailComTest extends \PHPUnit_Framework_TestCase
class GmailComTest extends TestCase
{
/**
* @dataProvider providerGetPrimaryEmail
Expand Down
53 changes: 53 additions & 0 deletions tests/Services/MailRUTest.php
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],
];
}
}
3 changes: 2 additions & 1 deletion tests/Services/MultiDomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\MultiDomain;
use PHPUnit\Framework\TestCase;

class MultiDomainTest extends \PHPUnit_Framework_TestCase
class MultiDomainTest extends TestCase
{
/**
* @dataProvider providerIsSupported
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/OutlookComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\OutlookCom;
use PHPUnit\Framework\TestCase;

class OutlookComTest extends \PHPUnit_Framework_TestCase
class OutlookComTest extends TestCase
{
/**
* @dataProvider providerIsSupported
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/Www33MailComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\Www33MailCom;
use PHPUnit\Framework\TestCase;

class Www33MailComTest extends \PHPUnit_Framework_TestCase
class Www33MailComTest extends TestCase
{
/**
* @dataProvider providerIsSupported
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/YahooComTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Services\YahooCom;
use PHPUnit\Framework\TestCase;

class YahooComTest extends \PHPUnit_Framework_TestCase
class YahooComTest extends TestCase
{
/**
* @dataProvider providerIsSupported
Expand Down
54 changes: 54 additions & 0 deletions tests/Services/YandexRuTest.php
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],
];
}
}
3 changes: 2 additions & 1 deletion tests/TransparentEmailFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use bkrukowski\TransparentEmail\Emails\Email;
use bkrukowski\TransparentEmail\Emails\EmailInterface;
use bkrukowski\TransparentEmail\TransparentEmailFactory;
use PHPUnit\Framework\TestCase;

class TransparentEmailFactoryTest extends \PHPUnit_Framework_TestCase
class TransparentEmailFactoryTest extends TestCase
{
/**
* @dataProvider providerExpectedEmail
Expand Down
3 changes: 2 additions & 1 deletion tests/TransparentEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use bkrukowski\TransparentEmail\Services\TlenPl;
use bkrukowski\TransparentEmail\TransparentEmail;
use bkrukowski\TransparentEmail\TransparentEmailFactory;
use PHPUnit\Framework\TestCase;

class TransparentEmailTest extends \PHPUnit_Framework_TestCase
class TransparentEmailTest extends TestCase
{
/**
* @dataProvider providerGetPrimaryEmail
Expand Down

0 comments on commit 30825ed

Please sign in to comment.