8000 [9.x] Implement Symfony Mailer by driesvints · Pull Request #38481 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] Implement Symfony Mailer #38481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f1d160f
Implement Symfony Mailer
driesvints Aug 20, 2021
9b70c70
Apply fixes from StyleCI
taylorotwell Aug 20, 2021
f9f8ad3
Update src/Illuminate/Mail/Message.php
driesvints Aug 21, 2021
b821c61
Update src/Illuminate/Mail/Message.php
driesvints Aug 21, 2021
d480103
Update src/Illuminate/Mail/Message.php
driesvints Aug 21, 2021
4abbc80
Update src/Illuminate/Mail/Message.php
driesvints Aug 21, 2021
e157c93
Update src/Illuminate/Mail/Message.php
driesvints Aug 21, 2021
eddfab4
Update Array and Log transports
driesvints Aug 23, 2021
1f68e4b
Apply fixes from StyleCI
taylorotwell Aug 23, 2021
c744477
Fix interface implementation
driesvints Aug 23, 2021
aa88fa1
Update Mailer
driesvints Aug 23, 2021
f6b10e1
Apply fixes from StyleCI
taylorotwell Aug 23, 2021
fa44414
Rename
driesvints Aug 23, 2021
ecea2e6
Remove method
driesvints Aug 23, 2021
9ef4747
Fix tests
driesvints Aug 23, 2021
0d8450e
Apply fixes from StyleCI
taylorotwell Aug 23, 2021
66ad5fa
Work on Mailer tests
driesvints Aug 24, 2021
c0220cd
type-hint
driesvints Aug 24, 2021
2463633
Fix Mailer tests
driesvints Aug 25, 2021
eb33afd
Fix more tests
driesvints Aug 25, 2021
b5aba0e
Apply fixes from StyleCI
taylorotwell Aug 25, 2021
f35a83c
Migrate Mailgun transport
driesvints Aug 27, 2021
58e7343
Migrate Postmark transport
driesvints Aug 27, 2021
17c7889
Replace SesTransport
driesvints Aug 30, 2021
8e87678
Remove transports from dev dependencies
driesvints Aug 30, 2021
3c1d1dc
Allow setting options on esmtp transport
driesvints Sep 2, 2021
66bbe6a
Fix Postmark transport
driesvints Sep 3, 2021
c2c97da
Fix embedding files
driesvints Sep 3, 2021
8724b1f
Clarify API transports
driesvints Sep 3, 2021
d61b7a9
Apply fixes from StyleCI
taylorotwell Sep 7, 2021
eb24e34
Fix SES transport setup
driesvints Sep 8, 2021
d6fc420
Add MessageStreamId to Postmark Transport again (#38748)
Jubeki Sep 10, 2021
c63ade9
Update symfony mailer docblocks (#38773)
Jubeki Sep 12, 2021
4ec09e5
Merge branch 'master' into symfony-mailer
driesvints Sep 13, 2021
78dccf1
Add Session Token to SES Transport (#38797)
Jubeki Sep 13, 2021
5e1baff
Update src/Illuminate/Mail/Transport/ArrayTransport.php
taylorotwell Sep 13, 2021
e23e57e
fix docblock
taylorotwell Sep 13, 2021
c8d1654
Add Wrapper for Symfony SentMessage (#38803)
Jubeki Sep 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
driesvints committed Sep 12, 2021
commit 9ef4747a4995b2ad43022326b90046196cffe2d0
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,6 @@ public function getSymfonyMessage()
*/
public function __call($method, $parameters)
{
return $this->forwardCallTo($this->email, $method, $parameters);
return $this->forwardCallTo($this->message, $method, $parameters);
}
}
22 changes: 6 additions & 16 deletions tests/Mail/MailFailoverTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Mail\Transport\ArrayTransport;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Mailer\Transport\FailoverTransport;
use Symfony\Component\Mailer\Transport\SendmailTransport;

class MailFailoverTransportTest extends TestCase
{
Expand All @@ -30,14 +32,8 @@ public function testGetFailoverTransportWithConfiguredTransports()
],
]);

$transport = app('mailer')->getSwiftMailer()->getTransport();
$this->assertInstanceOf(\Swift_FailoverTransport::class, $transport);

$transports = $transport->getTransports();
$this->assertCount(2, $transports);
$this->assertInstanceOf(\Swift_SendmailTransport::class, $transports[0]);
$this->assertEquals('/usr/sbin/sendmail -bs', $transports[0]->getCommand());
$this->assertInstanceOf(ArrayTransport::class, $transports[1]);
$transport = app('mailer')->getSymfonyTransport();
$this->assertInstanceOf(FailoverTransport::class, $transport);
}

public function testGetFailoverTransportWithLaravel6StyleMailConfiguration()
Expand All @@ -51,13 +47,7 @@ public function testGetFailoverTransportWithLaravel6StyleMailConfiguration()

$this->app['config']->set('mail.sendmail', '/usr/sbin/sendmail -bs');

$transport = app('mailer')->getSwiftMailer()->getTransport();
$this->assertInst 10000 anceOf(\Swift_FailoverTransport::class, $transport);

$transports = $transport->getTransports();
$this->assertCount(2, $transports);
$this->assertInstanceOf(\Swift_SendmailTransport::class, $transports[0]);
$this->assertEquals('/usr/sbin/sendmail -bs', $transports[0]->getCommand());
$this->assertInstanceOf(ArrayTransport::class, $transports[1]);
$transport = app('mailer')->getSymfonyTransport();
$this->assertInstanceOf(FailoverTransport::class, $transport);
}
}
4 changes: 2 additions & 2 deletions tests/Mail/MailLogTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetLogTransportWithConfiguredChannel()
'path' => 'mail.log',
]);

$transport = app('mailer')->getSwiftMailer()->getTransport();
$transport = app('mailer')->getSymfonyTransport();
$this->assertInstanceOf(LogTransport::class, $transport);

$logger = $transport->logger();
Expand All @@ -38,7 +38,7 @@ public function testGetLogTransportWithPsrLogger()
$this->app['config']->set('mail.driver', 'log');
$logger = $this->app->instance('log', new NullLogger);

$transportLogger = app('mailer')->getSwiftMailer()->getTransport()->logger();
$transportLogger = app('mailer')->getSymfonyTransport()->logger();

$this->assertEquals($logger, $transportLogger);
}
Expand Down
77 changes: 29 additions & 48 deletions tests/Mail/MailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
use Mockery as m;
use PHPUnit\Framework\TestCase;
use stdClass;
use Swift_Mime_Message;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;

class MailMessageTest extends TestCase
{
/**
* @var \Mockery::mock
*/
protected $swift;

/**
* @var \Illuminate\Mail\Message
*/
Expand All @@ -24,8 +20,7 @@ protected function setUp(): void
{
parent::setUp();

$this->swift = m::mock(Swift_Mime_Message::class);
$this->message = new Message($this->swift);
$this->message = new Message(new Email());
}

protected function tearDown(): void
Expand All @@ -35,89 +30,75 @@ protected function tearDown(): void

public function testFromMethod()
{
$this->swift->shouldReceive('setFrom')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->from('foo@bar.baz', 'Foo'));
$this->assertInstanceOf(Message::class, $message = $this->message->from('foo@bar.baz', 'Foo'));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getFrom()[0]);
}

public function testSenderMethod()
{
$this->swift->shouldReceive('setSender')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->sender('foo@bar.baz', 'Foo'));
$this->assertInstanceOf(Message::class, $message = $this->message->sender('foo@bar.baz', 'Foo'));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getSender());
}

public function testReturnPathMethod()
{
$this->swift->shouldReceive('setReturnPath')->once()->with('foo@bar.baz');
$this->assertInstanceOf(Message::class, $this->message->returnPath('foo@bar.baz'));
$this->assertInstanceOf(Message::class, $message = $this->message->returnPath('foo@bar.baz'));
$this->assertEquals(new Address('foo@bar.baz'), $message->getSymfonyMessage()->getReturnPath());
}

public function testToMethod()
{
$this->swift->shouldReceive('addTo')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->to('foo@bar.baz', 'Foo', false));
$this->assertInstanceOf(Message::class, $message = $this->message->to('foo@bar.baz', 'Foo', false));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getTo()[0]);
}

public function testToMethodWithOverride()
{
$this->swift->shouldReceive('setTo')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->to('foo@bar.baz', 'Foo', true));
$this->assertInstanceOf(Message::class, $message = $this->message->to('foo@bar.baz', 'Foo', true));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getTo()[0]);
}

public function testCcMethod()
{
$this->swift->shouldReceive('addCc')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->cc('foo@bar.baz', 'Foo'));
$this->assertInstanceOf(Message::class, $message = $this->message->cc('foo@bar.baz', 'Foo'));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getCc()[0]);
}

public function testBccMethod()
{
$this->swift->shouldReceive('addBcc')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->bcc('foo@bar.baz', 'Foo'));
$this->assertInstanceOf(Message::class, $message = $this->message->bcc('foo@bar.baz', 'Foo'));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getBcc()[0]);
}

public function testReplyToMethod()
{
$this->swift->shouldReceive('addReplyTo')->once()->with('foo@bar.baz', 'Foo');
$this->assertInstanceOf(Message::class, $this->message->replyTo('foo@bar.baz', 'Foo'));
$this->assertInstanceOf(Message::class, $message = $this->message->replyTo('foo@bar.baz', 'Foo'));
$this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getReplyTo()[0]);
}

public function testSubjectMethod()
{
$this->swift->shouldReceive('setSubject')->once()->with('foo');
$this->assertInstanceOf(Message::class, $this->message->subject('foo'));
$this->assertInstanceOf(Message::class, $message = $this->message->subject('foo'));
$this->assertEquals('foo', $message->getSymfonyMessage()->getSubject());
}

public function testPriorityMethod()
{
$this->swift->shouldReceive('setPriority')->once()->with(1);
$this->assertInstanceOf(Message::class, $this->message->priority(1));
}

public function testGetSwiftMessageMethod()
{
$this->assertInstanceOf(Swift_Mime_Message::class, $this->message->getSwiftMessage());
$this->assertInstanceOf(Message::class, $me 9E12 ssage = $this->message->priority(1));
$this->assertEquals(1, $message->getSymfonyMessage()->getPriority());
}

public function testBasicAttachment()
{
$swift = m::mock(stdClass::class);
$message = $this->getMockBuilder(Message::class)->onlyMethods(['createAttachmentFromPath'])->setConstructorArgs([$swift])->getMock();
$attachment = m::mock(stdClass::class);
$message->expects($this->once())->method('createAttachmentFromPath')->with($this->equalTo('foo.jpg'))->willReturn($attachment);
$swift->shouldReceive('attach')->once()->with($attachment);
$attachment->shouldReceive('setContentType')->once()->with('image/jpeg');
$attachment->shouldReceive('setFilename')->once()->with('bar.jpg');
$message->attach('foo.jpg', ['mime' => 'image/jpeg', 'as' => 'bar.jpg']);
$message = new Message(new Email());
$message->attach('foo.jpg', ['as' => 'foo.jpg', 'mime' => 'image/jpeg']);
}

public function testDataAttachment()
{
$swift = m::mock(stdClass::class);
$message = $this->getMockBuilder(Message::class)->onlyMethods(['createAttachmentFromData'])->setConstructorArgs([$swift])->getMock();
$attachment = m::mock(stdClass::class);
$message->expects($this->once())->method('createAttachmentFromData')->with($this->equalTo('foo'), $this->equalTo('name'))->willReturn($attachment);
$swift->shouldReceive('attach')->once()->with($attachment);
$attachment->shouldReceive('setContentType')->once()->with('image/jpeg');
$message->attachData('foo', 'name', ['mime' => 'image/jpeg']);
$message = new Message(new Email());
$message->attachData('foo', 'foo.jpg', ['mime' => 'image/jpeg']);

$this->assertEquals('foo', $message->getSymfonyMessage()->getAttachments()[0]->getBody());
}
}
4 changes: 2 additions & 2 deletions tests/Mail/MailableQueuedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Illuminate\Support\Testing\Fakes\QueueFake;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Swift_Mailer;
use Symfony\Component\Mailer\Transport\TransportInterface;

class MailableQueuedTest extends TestCase
{
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testQueuedMailableWithAttachmentFromDiskSent()

protected function getMocks()
{
return ['smtp', m::mock(Factory::class), m::mock(Swift_Mailer::class)];
return ['smtp', m::mock(Factory::class), m::mock(TransportInterface::class)];
}
}

Expand Down
0