Skip to content

Commit

Permalink
Do not read the notification we just inserted
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Feb 24, 2022
1 parent 9c45cf5 commit 240a5cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
3 changes: 1 addition & 2 deletions lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public function notify(INotification $notification): void {
$notificationId = $this->handler->add($notification);

try {
$notificationToPush = $this->handler->getById($notificationId, $notification->getUser());
$this->push->pushToDevice($notificationId, $notificationToPush);
$this->push->pushToDevice($notificationId, $notification);
} catch (NotificationNotFoundException $e) {
throw new \InvalidArgumentException('Error while preparing push notification');
}
Expand Down
15 changes: 3 additions & 12 deletions tests/Unit/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,21 @@ protected function setUp(): void {

public function dataNotify() {
return [
[23, 'user1'],
[42, 'user2'],
[23],
[42],
];
}

/**
* @dataProvider dataNotify
*
* @param int $id
* @param string $user
*/
public function testNotify($id, $user) {
$this->notification->expects($this->once())
->method('getUser')
->willReturn($user);

public function testNotify($id) {
$this->handler->expects($this->once())
->method('add')
->with($this->notification)
->willReturn($id);
$this->handler->expects($this->once())
->method('getById')
->with($id, $user)
->willReturn($this->notification);
$this->push->expects($this->once())
->method('pushToDevice')
->with($id, $this->notification);
Expand Down

0 comments on commit 240a5cd

Please sign in to comment.