Skip to content
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

[9.x] Fix Mailable->priority() #40917

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function locale($locale)
public function priority($level = 3)
{
$this->callbacks[] = function ($message) use ($level) {
$message->setPriority($level);
$message->priority($level);
};

return $this;
Expand Down
28 changes: 28 additions & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

namespace Illuminate\Tests\Mail;

use Illuminate\Contracts\View\Factory;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\Transport\ArrayTransport;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class MailMailableTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}

public function testMailableSetsRecipientsCorrectly()
{
$mailable = new WelcomeMailableStub;
Expand Down Expand Up @@ -417,6 +426,25 @@ public function testMailerMayBeSet()

$this->assertSame('array', $mailable->mailer);
}

public function testMailablePriorityGetsSent()
{
$view = m::mock(Factory::class);

$mailer = new Mailer('array', $view, new ArrayTransport);

$mailable = new WelcomeMailableStub;
$mailable->to('[email protected]');
$mailable->from('[email protected]');
$mailable->html('test content');

$mailable->priority(1);

$sentMessage = $mailer->send($mailable);

$this->assertSame('[email protected]', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress());
$this->assertStringContainsString('X-Priority: 1 (Highest)', $sentMessage->toString());
}
}

class WelcomeMailableStub extends Mailable
Expand Down