transparent-email/tests/TransparentEmailTest.php

60 lines
2.0 KiB
PHP
Raw Normal View History

2016-09-10 16:13:55 +03:00
<?php
namespace bkrukowski\TransparentEmail\Tests;
use bkrukowski\TransparentEmail\TransparentEmail;
use bkrukowski\TransparentEmail\InvalidEmailException;
class TransparentEmailTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerValidator
*
* @param string $email
* @param bool $validEmail
*/
public function testValidator(string $email, bool $validEmail)
{
if (!$validEmail) {
$this->expectException(InvalidEmailException::class);
}
(new TransparentEmail())->getPrimaryEmail($email);
}
public function providerValidator()
{
return [
['john.doe@gmail.comm', true],
['john doe@gmail.com', false],
];
}
/**
* @dataProvider providerGetPrimaryEmail
*
2016-09-13 19:23:07 +03:00
* @param TransparentEmail $transparentEmail
2016-09-10 16:13:55 +03:00
* @param string $email
* @param string $expectedEmail
*/
2016-09-13 19:23:07 +03:00
public function testGetPrimaryEmail(TransparentEmail $transparentEmail, string $email, string $expectedEmail)
2016-09-10 16:13:55 +03:00
{
2016-09-13 19:23:07 +03:00
$this->assertSame($expectedEmail, $transparentEmail->getPrimaryEmail($email));
2016-09-10 16:13:55 +03:00
}
public function providerGetPrimaryEmail()
{
return [
2016-09-10 16:18:48 +03:00
[
new TransparentEmail([TransparentEmail::SERVICE_TLEN_PL]),
'john.doe+alias@gmail.com',
'john.doe+alias@gmail.com'
],
2016-09-10 16:13:55 +03:00
[new TransparentEmail(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'],
[new TransparentEmail([]), 'John.Doe@example.com', 'john.doe@example.com'],
[new TransparentEmail([], true), 'John.Doe@example.com', 'John.Doe@example.com'],
[new TransparentEmail(TransparentEmail::ALL_SERVICES, true), 'John.Doe@gmail.com', 'johndoe@gmail.com'],
[new TransparentEmail(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'],
[new TransparentEmail(), 'Jane.Doe-receipts@yahoo.com', 'jane.doe@yahoo.com'],
];
}
}