Skip to content

Commit

Permalink
[5.6] Only set ID on NotificationFake if there is no ID set (#23470)
Browse files Browse the repository at this point in the history
* Only set ID on NotificationFake if there is no ID set

* StyleCI fix

* Add a test
  • Loading branch information
Adam Campbell authored and taylorotwell committed Mar 9, 2018
1 parent 195ba6a commit 8a06746
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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) {
$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

0 comments on commit 8a06746

Please sign in to comment.