-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
6be4c93
commit 71affc3
Showing
6 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* @author Alexey Samoylov <alexey.samoylov@gmail.com> | ||
*/ | ||
class SendMessageJobTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** @var \YarCode\Yii2\QueueMailer\Mailer */ | ||
public $mailer; | ||
/** @var \yii\mail\MessageInterface */ | ||
public $message; | ||
/** @var \YarCode\Yii2\QueueMailer\Jobs\SendMessageJob */ | ||
public $a; | ||
|
||
/** | ||
* @throws \yii\base\InvalidConfigException | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->mailer = \Yii::createObject([ | ||
'class' => \YarCode\Yii2\QueueMailer\Mailer::class, | ||
'queue' => [ | ||
'class' => \yii\queue\sync\Queue::class, | ||
'handle' => false, // whether tasks should be executed immediately | ||
], | ||
'syncMailer' => [ | ||
'class' => \yii\swiftmailer\Mailer::class, | ||
'useFileTransport' => true, | ||
], | ||
]); | ||
|
||
$this->message = $this->mailer->compose(); | ||
$this->message->setTo('test@example.org'); | ||
$this->message->setFrom('no-reply@example.org'); | ||
$this->message->setHtmlBody('test message'); | ||
|
||
$this->a = \Yii::createObject([ | ||
'class' => \YarCode\Yii2\QueueMailer\Jobs\SendMessageJob::class, | ||
'mailer' => $this->mailer, | ||
'message' => $this->message, | ||
]); | ||
} | ||
|
||
protected function tearDown()/* The :void return type declaration that should be here would cause a BC issue */ | ||
{ | ||
\yii\helpers\FileHelper::removeDirectory(Yii::getAlias('@runtime/mail')); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$this->assertTrue($this->a->execute($this->mailer->queue)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* @author Alexey Samoylov <alexey.samoylov@gmail.com> | ||
*/ | ||
class SendMultipleMessagesJobTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** @var \YarCode\Yii2\QueueMailer\Mailer */ | ||
public $mailer; | ||
/** @var \yii\mail\MessageInterface */ | ||
public $message; | ||
/** @var \yii\mail\MessageInterface */ | ||
public $message2; | ||
/** @var \YarCode\Yii2\QueueMailer\Jobs\SendMessageJob */ | ||
public $a; | ||
|
||
/** | ||
* @throws \yii\base\InvalidConfigException | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->mailer = \Yii::createObject([ | ||
'class' => \YarCode\Yii2\QueueMailer\Mailer::class, | ||
'queue' => [ | ||
'class' => \yii\queue\sync\Queue::class, | ||
'handle' => false, // whether tasks should be executed immediately | ||
], | ||
'syncMailer' => [ | ||
'class' => \yii\swiftmailer\Mailer::class, | ||
'useFileTransport' => true, | ||
], | ||
]); | ||
|
||
$this->message = $this->mailer->compose(); | ||
$this->message->setTo('test@example.org'); | ||
$this->message->setFrom('no-reply@example.org'); | ||
$this->message->setHtmlBody('test message'); | ||
|
||
$this->message2 = $this->mailer->compose(); | ||
$this->message2->setTo('test@example.org'); | ||
$this->message2->setFrom('no-reply@example.org'); | ||
$this->message2->setHtmlBody('test message 2'); | ||
|
||
$this->a = \Yii::createObject([ | ||
'class' => \YarCode\Yii2\QueueMailer\Jobs\SendMultipleMessagesJob::class, | ||
'mailer' => $this->mailer, | ||
'messages' => [ | ||
$this->message, | ||
$this->message2, | ||
], | ||
]); | ||
} | ||
|
||
protected function tearDown()/* The :void return type declaration that should be here would cause a BC issue */ | ||
{ | ||
try { | ||
\yii\helpers\FileHelper::removeDirectory(Yii::getAlias('@runtime/mail')); | ||
} catch (\Throwable $e) {} | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$this->assertEquals(2, $this->a->execute($this->mailer->queue)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<?php | ||
// ensure we get report on all possible php errors | ||
error_reporting(-1); | ||
|
||
define('YII_ENV', 'test'); | ||
defined('YII_DEBUG') or define('YII_DEBUG', true); | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
require_once __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; | ||
|
||
\Yii::setAlias('@runtime', __DIR__ . DIRECTORY_SEPARATOR . 'runtime'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |