Exemple #1
0
 public function testNotificationPushMessage()
 {
     $message = new Message(['title_loc_key' => 'MESSAGE_TITLE']);
     $notification = new Notification($message, []);
     $pushMessage = $this->builder->buildPushMessage(['my_token'], $notification);
     self::assertInstanceOf(GcmMessage::class, $pushMessage);
     self::assertEquals('MESSAGE_TITLE', $pushMessage->getNotificationPayload()['title_loc_key']);
 }
Exemple #2
0
 /**
  * Get service formatted push messages.
  *
  * @param \Jgut\Tify\Notification $notification
  *
  * @throws \ZendService\Google\Exception\InvalidArgumentException
  * @throws \ZendService\Google\Exception\RuntimeException
  *
  * @return \Generator
  */
 protected function getPushMessages(Notification $notification)
 {
     foreach (array_chunk($notification->getReceivers(), 100) as $receivers) {
         $tokens = array_map(function ($receiver) {
             return $receiver instanceof GcmReceiver ? $receiver->getToken() : null;
         }, $receivers);
         (yield $this->builder->buildPushMessage(array_filter($tokens), $notification));
     }
 }