Move Mailer error tests to unit [MAILPOET-2009]

This commit is contained in:
wxa
2019-04-25 11:10:29 +03:00
committed by M. Shull
parent f2e0dc7d2f
commit 994fae79d2
14 changed files with 59 additions and 24 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
use Codeception\Stub;
use MailPoet\Mailer\MailerError;
use MailPoet\Mailer\Methods\ErrorMappers\PHPMailMapper;
use MailPoet\WP\Functions as WPFunctions;
class PHPMailMapperTest extends \MailPoetUnitTest {
/** @var PHPMailMapper*/
private $mapper;
function _before() {
parent::_before();
$this->mapper = new PHPMailMapper();
WPFunctions::set(Stub::make(new WPFunctions, [
'__' => function ($value) {
return $value;
}
]));
}
function testGetProperErrorForSubscriber() {
$error = $this->mapper->getErrorForSubscriber('john@rambo.com');
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
expect($error->getMessage())->equals('PHPMail has returned an unknown error.');
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
}
function testGetProperErrorFromException() {
$error = $this->mapper->getErrorFromException(new \Exception('Some message'), 'john@rambo.com');
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
expect($error->getMessage())->equals('Some message');
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
}
function testGetSoftErrorFromExceptionForInvalidEmail() {
$error = $this->mapper->getErrorFromException(new \Exception('Invalid address. (Add ...'), 'john@rambo.com');
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
}
function _after() {
WPFunctions::set(new WPFunctions);
}
}