-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force reconnection to fix mailing on daemon queues.
- Loading branch information
1 parent
bc924d5
commit af8eb1f
Showing
2 changed files
with
43 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,14 @@ public function testMailerSendSendsMessageWithProperViewContent() | |
{ | ||
unset($_SERVER['__mailer.test']); | ||
$mailer = $this->getMock('Illuminate\Mail\Mailer', array('createMessage'), $this->getMocks()); | ||
$message = m::mock('StdClass'); | ||
$message = m::mock('Swift_Mime_Message'); | ||
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); | ||
$view = m::mock('StdClass'); | ||
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', array('data', 'message' => $message))->andReturn($view); | ||
$view->shouldReceive('render')->once()->andReturn('rendered.view'); | ||
$message->shouldReceive('setBody')->once()->with('rendered.view', 'text/html'); | ||
$message->shouldReceive('setFrom')->never(); | ||
$mailer->setSwiftMailer(m::mock('StdClass')); | ||
$this->setSwiftMailer($mailer); | ||
$message->shouldReceive('getSwiftMessage')->once()->andReturn($message); | ||
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with($message, array()); | ||
$mailer->send('foo', array('data'), function($m) { $_SERVER['__mailer.test'] = $m; }); | ||
|
@@ -34,7 +34,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContent() | |
{ | ||
unset($_SERVER['__mailer.test']); | ||
$mailer = $this->getMock('Illuminate\Mail\Mailer', array('createMessage'), $this->getMocks()); | ||
$message = m::mock('StdClass'); | ||
$message = m::mock('Swift_Mime_Message'); | ||
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); | ||
$view = m::mock('StdClass'); | ||
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', array('data', 'message' => $message))->andReturn($view); | ||
|
@@ -43,7 +43,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContent() | |
$message->shouldReceive('setBody')->once()->with('rendered.view', 'text/html'); | ||
$message->shouldReceive('addPart')->once()->with('rendered.view', 'text/plain'); | ||
$message->shouldReceive('setFrom')->never(); | ||
$mailer->setSwiftMailer(m::mock('StdClass')); | ||
$this->setSwiftMailer($mailer); | ||
$message->shouldReceive('getSwiftMessage')->once()->andReturn($message); | ||
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with($message, array()); | ||
$mailer->send(array('foo', 'bar'), array('data'), function($m) { $_SERVER['__mailer.test'] = $m; }); | ||
|
@@ -55,7 +55,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContentWhenExplicit | |
{ | ||
unset($_SERVER['__mailer.test']); | ||
$mailer = $this->getMock('Illuminate\Mail\Mailer', array('createMessage'), $this->getMocks()); | ||
$message = m::mock('StdClass'); | ||
$message = m::mock('Swift_Mime_Message'); | ||
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); | ||
$view = m::mock('StdClass'); | ||
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', array('data', 'message' => $message))->andReturn($view); | ||
|
@@ -64,7 +64,7 @@ public function testMailerSendSendsMessageWithProperPlainViewContentWhenExplicit | |
$message->shouldReceive('setBody')->once()->with('rendered.view', 'text/html'); | ||
$message->shouldReceive('addPart')->once()->with('rendered.view', 'text/plain'); | ||
$message->shouldReceive('setFrom')->never(); | ||
$mailer->setSwiftMailer(m::mock('StdClass')); | ||
$this->setSwiftMailer($mailer); | ||
$message->shouldReceive('getSwiftMessage')->once()->andReturn($message); | ||
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with($message, array()); | ||
$mailer->send(array('html' => 'foo', 'text' => 'bar'), array('data'), function($m) { $_SERVER['__mailer.test'] = $m; }); | ||
|
@@ -131,14 +131,14 @@ public function testMailerCanQueueMessagesToItselfLaterOnAnotherQueue() | |
public function testMessagesCanBeLoggedInsteadOfSent() | ||
{ | ||
$mailer = $this->getMock('Illuminate\Mail\Mailer', array('createMessage'), $this->getMocks()); | ||
$message = m::mock('StdClass'); | ||
$message = m::mock('Swift_Mime_Message'); | ||
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); | ||
$view = m::mock('StdClass'); | ||
$mailer->getViewFactory()->shouldReceive('make')->once()->with('foo', array('data', 'message' => $message))->andReturn($view); | ||
$view->shouldReceive('render')->once()->andReturn('rendered.view'); | ||
$message->shouldReceive('setBody')->once()->with('rendered.view', 'text/html'); | ||
$message->shouldReceive('setFrom')->never(); | ||
$mailer->setSwiftMailer(m::mock('StdClass')); | ||
$this->setSwiftMailer($mailer); | ||
$message->shouldReceive('getTo')->once()->andReturn(array('[email protected]' => 'Taylor')); | ||
$message->shouldReceive('getSwiftMessage')->once()->andReturn($message); | ||
$mailer->getSwiftMailer()->shouldReceive('send')->never(); | ||
|
@@ -154,7 +154,7 @@ public function testMessagesCanBeLoggedInsteadOfSent() | |
public function testMailerCanResolveMailerClasses() | ||
{ | ||
$mailer = $this->getMock('Illuminate\Mail\Mailer', array('createMessage'), $this->getMocks()); | ||
$message = m::mock('StdClass'); | ||
$message = m::mock('Swift_Mime_Message'); | ||
$mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); | ||
$view = m::mock('StdClass'); | ||
$container = new Illuminate\Container\Container; | ||
|
@@ -169,7 +169,7 @@ public function testMailerCanResolveMailerClasses() | |
$view->shouldReceive('render')->once()->andReturn('rendered.view'); | ||
$message->shouldReceive('setBody')->once()->with('rendered.view', 'text/html'); | ||
$message->shouldReceive('setFrom')->never(); | ||
$mailer->setSwiftMailer(m::mock('StdClass')); | ||
$this->setSwiftMailer($mailer); | ||
$message->shouldReceive('getSwiftMessage')->once()->andReturn($message); | ||
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with($message, array()); | ||
$mailer->send('foo', array('data'), 'FooMailer'); | ||
|
@@ -183,7 +183,7 @@ public function testGlobalFromIsRespectedOnAllMessages() | |
$view = m::mock('StdClass'); | ||
$mailer->getViewFactory()->shouldReceive('make')->once()->andReturn($view); | ||
$view->shouldReceive('render')->once()->andReturn('rendered.view'); | ||
$mailer->setSwiftMailer(m::mock('StdClass')); | ||
$this->setSwiftMailer($mailer); | ||
$mailer->alwaysFrom('[email protected]', 'Taylor Otwell'); | ||
$me = $this; | ||
$mailer->getSwiftMailer()->shouldReceive('send')->once()->with(m::type('Swift_Message'), array())->andReturnUsing(function($message) use ($me) | ||
|
@@ -198,6 +198,8 @@ public function testFailedRecipientsAreAppendedAndCanBeRetrieved() | |
{ | ||
unset($_SERVER['__mailer.test']); | ||
$mailer = $this->getMailer(); | ||
$mailer->getSwiftMailer()->shouldReceive('getTransport')->andReturn($transport = m::mock('Swift_Transport')); | ||
$transport->shouldReceive('stop'); | ||
$view = m::mock('StdClass'); | ||
$mailer->getViewFactory()->shouldReceive('make')->once()->andReturn($view); | ||
$view->shouldReceive('render')->once()->andReturn('rendered.view'); | ||
|
@@ -216,6 +218,16 @@ protected function getMailer() | |
} | ||
|
||
|
||
public function setSwiftMailer($mailer) | ||
{ | ||
$swift = m::mock('Swift_Mailer'); | ||
$swift->shouldReceive('getTransport')->andReturn($transport = m::mock('Swift_Transport')); | ||
$transport->shouldReceive('stop'); | ||
$mailer->setSwiftMailer($swift); | ||
return $mailer; | ||
} | ||
|
||
|
||
protected function getMocks() | ||
{ | ||
return array(m::mock('Illuminate\Contracts\View\Factory'), m::mock('Swift_Mailer')); | ||
|
@@ -229,4 +241,10 @@ public function send($message, &$failed) | |
{ | ||
$failed[] = '[email protected]'; | ||
} | ||
public function getTransport() | ||
{ | ||
$transport = m::mock('Swift_Transport'); | ||
$transport->shouldReceive('stop'); | ||
return $transport; | ||
} | ||
} |
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylorotwell Under what conditions would there be mailer errors without the reconnect? Just noticed this commit and I'm curious about the reasons behind it.
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the queue:worker in daemon mode attempts to send queued emails.
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewdaniel and it would always fail before this commit?
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylorotwell any chance of this seeing a tagged 5.0 release?
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A 5.0.x tag will be coming shortly, I'm sure. In the meanwhile, you can append
@dev
to your version constraint for laravel if you really need this fix.af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 :)
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TY! 👍
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why I have this is my Code but I still get errors?
af8eb1f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same : fwrite(): send of 30 bytes failed with errno=32 Broken pipe in /var/www/html/prod/forcebook/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:232
Latest version of 5.2