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

[5.6] Only set ID on NotificationFake if there is no ID set #23470

Merged
merged 3 commits into from
Mar 9, 2018
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
4 changes: 3 additions & 1 deletion src/Illuminate/Support/Testing/Fakes/NotificationFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ public function sendNow($notifiables, $notification)
}

foreach ($notifiables as $notifiable) {
$notification->id = Uuid::uuid4()->toString();
if (! $notification->id) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might sound a bit nitpicky, but wouldn't checking for null be preferable here to allow '0' to be used as an ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well a UUID would never be 0, so not sure that makes sense.

$notification->id = Uuid::uuid4()->toString();
}

$this->notifications[get_class($notifiable)][$notifiable->getKey()][get_class($notification)][] = [
'notification' => $notification,
Expand Down
20 changes: 20 additions & 0 deletions tests/Support/SupportTestingNotificationFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ public function testAssertNotSentTo()
$this->assertThat($e, new ExceptionMessage('The unexpected [Illuminate\Tests\Support\NotificationStub] notification was sent.'));
}
}

public function testResettingNotificationId()
{
$notification = new NotificationStub();

$this->fake->send($this->user, $notification);

$id = $notification->id;

$this->fake->send($this->user, $notification);

$this->assertSame($id, $notification->id);

$notification->id = null;

$this->fake->send($this->user, $notification);

$this->assertNotNull($notification->id);
$this->assertNotSame($id, $notification->id);
}
}

class NotificationStub extends Notification
Expand Down