Skip to content

Commit

Permalink
changed event class name
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyzhu committed Oct 31, 2020
1 parent c3fa2d4 commit 6d17185
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,4 @@ Mail::to($request->user())->send(new OrderShipped($order));
<a name="events"></a>
## 事件

在发送邮件消息的时候,组件会触发两个事件。`MessageSending` 事件在发送消息前触发,`MessageSent` 事件在消息发送完成后触发。记住,这些事件都是在邮件被**发送**时触发,而不是在队列化的时候。
在发送邮件消息的时候,组件会触发两个事件。`MailMessageSending` 事件在发送消息前触发,`MailMessageSent` 事件在消息发送完成后触发。记住,这些事件都是在邮件被**发送**时触发,而不是在队列化的时候。
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Swift_Message;

class MessageSending
class MailMessageSending
{
/**
* The Swift message instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Swift_Attachment;
use Swift_Message;

class MessageSent
class MailMessageSent
{
/**
* The Swift message instance.
Expand Down
8 changes: 4 additions & 4 deletions src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use HyperfExt\Mail\Concerns\PendingMailable;
use HyperfExt\Mail\Contracts\MailableInterface;
use HyperfExt\Mail\Contracts\MailerInterface;
use HyperfExt\Mail\Events\MessageSending;
use HyperfExt\Mail\Events\MessageSent;
use HyperfExt\Mail\Events\MailMessageSending;
use HyperfExt\Mail\Events\MailMessageSent;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Swift_Mailer;
Expand Down Expand Up @@ -178,11 +178,11 @@ public function sendNow(MailableInterface $mailable): ?array
// its recipients. We will then fire the sent event for the sent message.
$swiftMessage = $message->getSwiftMessage();

$this->eventDispatcher->dispatch(new MessageSending($swiftMessage, $data));
$this->eventDispatcher->dispatch(new MailMessageSending($swiftMessage, $data));

$this->sendSwiftMessage($swiftMessage, $failedRecipients);

$this->eventDispatcher->dispatch(new MessageSent($swiftMessage, $data));
$this->eventDispatcher->dispatch(new MailMessageSent($swiftMessage, $data));

return $failedRecipients;
}
Expand Down
20 changes: 10 additions & 10 deletions tests/MailMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

use Hyperf\Utils\ApplicationContext;
use HyperfExt\Mail\Contracts\MailableInterface;
use HyperfExt\Mail\Events\MessageSending;
use HyperfExt\Mail\Events\MessageSent;
use HyperfExt\Mail\Events\MailMessageSending;
use HyperfExt\Mail\Events\MailMessageSent;
use HyperfExt\Mail\Mailer;
use Mockery as m;
use PHPUnit\Framework\TestCase;
Expand All @@ -39,8 +39,8 @@ public function testGlobalFromIsRespectedOnAllMessages()
$mailable = m::mock(MailableInterface::class);
$mailable->shouldReceive('handler')->once()->andReturn(null);
$events = ApplicationContext::getContainer()->get(EventDispatcherInterface::class);
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSent::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSent::class));
$mailer = $this->getMailer();
$this->setSwiftMailer($mailer);
$mailer->setAlwaysFrom('eric@zhu.email', 'Taylor Otwell');
Expand All @@ -56,8 +56,8 @@ public function testGlobalReturnPathIsRespectedOnAllMessages()
$mailable = m::mock(MailableInterface::class);
$mailable->shouldReceive('handler')->once()->andReturn(null);
$events = ApplicationContext::getContainer()->get(EventDispatcherInterface::class);
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSent::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSent::class));
$mailer = $this->getMailer();
$this->setSwiftMailer($mailer);
$mailer->setAlwaysReturnPath('eric@zhu.email');
Expand All @@ -73,8 +73,8 @@ public function testFailedRecipientsAreAppendedAndCanBeRetrieved()
$mailable = m::mock(MailableInterface::class);
$mailable->shouldReceive('handler')->once()->andReturn(null);
$events = ApplicationContext::getContainer()->get(EventDispatcherInterface::class);
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSent::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSent::class));
$mailer = $this->getMailer();
$mailer->getSwiftMailer()->shouldReceive('getTransport')->andReturn($transport = m::mock(Swift_Transport::class));
$transport->shouldReceive('stop');
Expand All @@ -93,8 +93,8 @@ public function testEventsAreDispatched()
$mailable = m::mock(MailableInterface::class);
$mailable->shouldReceive('handler')->once()->andReturn(null);
$events = ApplicationContext::getContainer()->get(EventDispatcherInterface::class);
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MessageSent::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSending::class));
$events->shouldReceive('dispatch')->once()->with(m::type(MailMessageSent::class));
$mailer = $this->getMailer($events);
$this->setSwiftMailer($mailer);
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with(m::type(Swift_Message::class), []);
Expand Down

0 comments on commit 6d17185

Please sign in to comment.