LaravelFCM\Sender\FCMSender::sendToTopic PHP Method

sendToTopic() public method

Send message devices registered at a or more topics
public sendToTopic ( Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null ) : TopicResponse
$topics LaravelFCM\Message\Topics
$options LaravelFCM\Message\Options
$notification LaravelFCM\Message\PayloadNotification
$data LaravelFCM\Message\PayloadData
return LaravelFCM\Response\TopicResponse
    public function sendToTopic(Topics $topics, Options $options = null, PayloadNotification $notification = null, PayloadData $data = null)
    {
        $request = new Request(null, $options, $notification, $data, $topics);
        $responseGuzzle = $this->post($request);
        return new TopicResponse($responseGuzzle, $topics);
    }

Usage Example

コード例 #1
0
ファイル: TopicsTest.php プロジェクト: brozot/laravel-fcm
 /**
  * @test
  */
 public function it_send_a_notification_to_a_topic_and_return_error()
 {
     $response = new Response(200, [], '{"error":"TopicsMessageRateExceeded"}');
     $client = Mockery::mock(Client::class);
     $client->shouldReceive('post')->once()->andReturn($response);
     $fcm = new FCMSender($client, 'http://test.test');
     $topics = new Topics();
     $topics->topic('test');
     $response = $fcm->sendToTopic($topics);
     $this->assertFalse($response->isSuccess());
     $this->assertTrue($response->shouldRetry());
     $this->assertEquals('TopicsMessageRateExceeded', $response->error());
 }