mirror of
https://github.com/retailcrm/transparent-email.git
synced 2024-11-28 08:16:03 +03:00
Removing static dependencies
This commit is contained in:
parent
5dd7f4d0fb
commit
9fe99a091c
@ -27,7 +27,8 @@ use bkrukowski\TransparentEmail\Emails\EmailInterface;
|
|||||||
use bkrukowski\TransparentEmail\Emails\InvalidEmailException;
|
use bkrukowski\TransparentEmail\Emails\InvalidEmailException;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$cleaner = TransparentEmailFactory::createDefault();
|
$factory = new TransparentEmailFactory();
|
||||||
|
$cleaner = $factory->createDefault();
|
||||||
$inputEmail = new Email('John.Doe+alias@gmail.com');
|
$inputEmail = new Email('John.Doe+alias@gmail.com');
|
||||||
/** @var EmailInterface $transformedEmail */
|
/** @var EmailInterface $transformedEmail */
|
||||||
$transformedEmail = $cleaner->getPrimaryEmail($inputEmail);
|
$transformedEmail = $cleaner->getPrimaryEmail($inputEmail);
|
||||||
|
@ -13,23 +13,23 @@ use bkrukowski\TransparentEmail\Services\YahooCom;
|
|||||||
|
|
||||||
class TransparentEmailFactory
|
class TransparentEmailFactory
|
||||||
{
|
{
|
||||||
public static function createDefault() : TransparentEmailInterface
|
public function createDefault() : TransparentEmailInterface
|
||||||
{
|
{
|
||||||
return new TransparentEmail(self::createServiceCollector());
|
return new TransparentEmail($this->createServiceCollector());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createServiceCollector() : ServiceCollectorInterface
|
private function createServiceCollector() : ServiceCollectorInterface
|
||||||
{
|
{
|
||||||
$collector = new ServiceCollector();
|
$collector = new ServiceCollector();
|
||||||
|
|
||||||
foreach (self::getAllServicesClasses() as $servicesClass) {
|
foreach ($this->getAllServicesClasses() as $servicesClass) {
|
||||||
$collector->addService(new $servicesClass());
|
$collector->addService(new $servicesClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collector;
|
return $collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getAllServicesClasses() : array
|
private function getAllServicesClasses() : array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
GmailCom::class,
|
GmailCom::class,
|
||||||
|
@ -18,7 +18,7 @@ class TransparentEmailFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testExpectedEmail(EmailInterface $inputEmail, string $expectedEmail)
|
public function testExpectedEmail(EmailInterface $inputEmail, string $expectedEmail)
|
||||||
{
|
{
|
||||||
$outputEmail = TransparentEmailFactory::createDefault()->getPrimaryEmail($inputEmail);
|
$outputEmail = (new TransparentEmailFactory())->createDefault()->getPrimaryEmail($inputEmail);
|
||||||
$this->assertSame($expectedEmail, (string) $outputEmail);
|
$this->assertSame($expectedEmail, (string) $outputEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +42,12 @@ class TransparentEmailTest extends \PHPUnit_Framework_TestCase
|
|||||||
'john.doe+alias@gmail.com',
|
'john.doe+alias@gmail.com',
|
||||||
'john.doe+alias@gmail.com'
|
'john.doe+alias@gmail.com'
|
||||||
],
|
],
|
||||||
[TransparentEmailFactory::createDefault(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'],
|
[(new TransparentEmailFactory())->createDefault(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'],
|
||||||
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'john.doe@example.com'],
|
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'john.doe@example.com'],
|
||||||
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'John.Doe@example.com', true],
|
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'John.Doe@example.com', true],
|
||||||
[TransparentEmailFactory::createDefault(), 'John.Doe@gmail.com', 'johndoe@gmail.com', true],
|
[(new TransparentEmailFactory())->createDefault(), 'John.Doe@gmail.com', 'johndoe@gmail.com', true],
|
||||||
[TransparentEmailFactory::createDefault(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'],
|
[(new TransparentEmailFactory())->createDefault(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'],
|
||||||
[TransparentEmailFactory::createDefault(), 'Jane.Doe-receipts@yahoo.com', 'jane.doe@yahoo.com'],
|
[(new TransparentEmailFactory())->createDefault(), 'Jane.Doe-receipts@yahoo.com', 'jane.doe@yahoo.com'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class TransparentEmailTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDefault(EmailInterface $inputEmail, string $expectedEmail)
|
public function testDefault(EmailInterface $inputEmail, string $expectedEmail)
|
||||||
{
|
{
|
||||||
$this->assertEquals($expectedEmail, (TransparentEmailFactory::createDefault())->getPrimaryEmail($inputEmail));
|
$this->assertEquals($expectedEmail, ((new TransparentEmailFactory())->createDefault())->getPrimaryEmail($inputEmail));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerDefault() : array
|
public function providerDefault() : array
|
||||||
|
Loading…
Reference in New Issue
Block a user