-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[10.x] Allow serialization of NotificationSent #47375
Merged
taylorotwell
merged 4 commits into
laravel:10.x
from
cosmastech:serializable-sent-message
Jun 13, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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,78 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Mail; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Notifications\Events\NotificationSent; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notifiable; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Schema; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class SentMessageMailTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('sent_message_users', function (Blueprint $table) { | ||
$table->increments('id'); | ||
}); | ||
} | ||
|
||
public function testDispatchesNotificationSent() | ||
{ | ||
$notificationWasSent = false; | ||
|
||
$user = SentMessageUser::create(); | ||
|
||
Event::listen( | ||
NotificationSent::class, | ||
function(NotificationSent $notification) use (&$notificationWasSent, $user) { | ||
$notificationWasSent = true; | ||
/** | ||
* Confirm that NotificationSent can be serialized/unserialized as | ||
* will happen if the listener implements ShouldQueue. | ||
*/ | ||
/** @var NotificationSent $afterSerialization */ | ||
$afterSerialization = unserialize(serialize($notification)); | ||
|
||
$this->assertTrue($user->is($afterSerialization->notifiable)); | ||
|
||
$this->assertEqualsCanonicalizing($notification->notification, $afterSerialization->notification); | ||
}); | ||
|
||
$user->notify(new SentMessageMailNotification()); | ||
|
||
$this->assertTrue($notificationWasSent); | ||
} | ||
} | ||
|
||
class SentMessageUser extends Model | ||
{ | ||
use Notifiable; | ||
|
||
public $timestamps = false; | ||
} | ||
|
||
|
||
class SentMessageMailNotification extends Notification | ||
{ | ||
public function via(): array | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
public function toMail(object $notifiable): MailMessage | ||
{ | ||
return (new MailMessage) | ||
->line('Example notification with attachment.') | ||
->attach(__DIR__ . '/Fixtures/blank_document.pdf', [ | ||
'as' => 'blank_document.pdf', | ||
'mime' => 'application/pdf', | ||
]); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This never needs to be base 64 encoded and serialized anymore?
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.
Admittedly, I don't know all of the use cases here, but my thinking is: if
SentMessage
is being base64_encoded for attachments when it is serialized, then there's no need to encode it again whenMessageSent
is being serialized.Do you see a flaw in that thinking?
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.
Yeah, that could be true.