update 1.0.8.0
Commits for version update
This commit is contained in:
@@ -23,13 +23,10 @@ class ResponseTest extends FCMTestCase {
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('post')->once()->andReturn($response);
|
||||
$this->app->singleton('fcm.client', function($app) use($client) {
|
||||
return $client;
|
||||
});
|
||||
|
||||
$tokens = 'uniqueToken';
|
||||
|
||||
$fcm = new FCMSender();
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
$fcm->sendTo($tokens);
|
||||
}
|
||||
|
||||
@@ -56,16 +53,41 @@ class ResponseTest extends FCMTestCase {
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('post')->times(10)->andReturn($response);
|
||||
$this->app->singleton('fcm.client', function($app) use($client) {
|
||||
return $client;
|
||||
});
|
||||
|
||||
$tokens = [];
|
||||
for ($i=0 ; $i<10000 ; $i++) {
|
||||
$tokens[$i] = 'token_'.$i;
|
||||
}
|
||||
|
||||
$fcm = new FCMSender();
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
$fcm->sendTo($tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function an_empty_array_of_tokens_thrown_an_exception()
|
||||
{
|
||||
$response = new Response(400, [], '{
|
||||
"multicast_id": 216,
|
||||
"success": 3,
|
||||
"failure": 3,
|
||||
"canonical_ids": 1,
|
||||
"results": [
|
||||
{ "message_id": "1:0408" },
|
||||
{ "error": "Unavailable" },
|
||||
{ "error": "InvalidRegistration" },
|
||||
{ "message_id": "1:1516" },
|
||||
{ "message_id": "1:2342", "registration_id": "32" },
|
||||
{ "error": "NotRegistered"}
|
||||
]
|
||||
}' );
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('post')->once()->andReturn($response);
|
||||
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
$this->setExpectedException(\LaravelFCM\Response\Exceptions\InvalidRequestException::class);
|
||||
$fcm->sendTo([]);
|
||||
}
|
||||
}
|
@@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase;
|
||||
|
||||
abstract class FCMTestCase extends Illuminate\Foundation\Testing\TestCase {
|
||||
abstract class FCMTestCase extends TestCase {
|
||||
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
|
||||
|
||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||
$app->register(LaravelFCM\FCMServiceProvider::class);
|
||||
|
||||
$app['config']['fcm.driver'] = 'http';
|
||||
$app['config']['fcm.http.timeout'] = 20;
|
||||
$app['config']['fcm.http.server_send_url'] = 'http://test.test';
|
||||
@@ -16,4 +19,5 @@ abstract class FCMTestCase extends Illuminate\Foundation\Testing\TestCase {
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
}
|
@@ -9,7 +9,6 @@ class GroupResponseTest extends FCMTestCase {
|
||||
*/
|
||||
public function it_construct_a_response_with_successes()
|
||||
{
|
||||
|
||||
$notificationKey = "notificationKey";
|
||||
|
||||
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
|
||||
@@ -29,7 +28,6 @@ class GroupResponseTest extends FCMTestCase {
|
||||
*/
|
||||
public function it_construct_a_response_with_failures()
|
||||
{
|
||||
|
||||
$notificationKey = "notificationKey";
|
||||
|
||||
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
|
||||
@@ -55,7 +53,6 @@ class GroupResponseTest extends FCMTestCase {
|
||||
*/
|
||||
public function it_construct_a_response_with_partials_failures()
|
||||
{
|
||||
|
||||
$notificationKey = "notificationKey";
|
||||
|
||||
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
|
||||
|
14
vendor/brozot/laravel-fcm/tests/TopicsTest.php
vendored
14
vendor/brozot/laravel-fcm/tests/TopicsTest.php
vendored
@@ -17,7 +17,6 @@ class TopicsTest extends FCMTestCase {
|
||||
|
||||
$this->setExpectedException(NoTopicProvidedException::class);
|
||||
$topics->build();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,7 +31,6 @@ class TopicsTest extends FCMTestCase {
|
||||
$topics->topic('myTopic');
|
||||
|
||||
$this->assertEquals($target, $topics->build());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,12 +113,8 @@ class TopicsTest extends FCMTestCase {
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('post')->once()->andReturn($response);
|
||||
$this->app->singleton('fcm.client', function($app) use($client) {
|
||||
return $client;
|
||||
});
|
||||
|
||||
|
||||
$fcm = new FCMSender();
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
|
||||
$topics = new Topics();
|
||||
$topics->topic('test');
|
||||
@@ -141,12 +135,8 @@ class TopicsTest extends FCMTestCase {
|
||||
|
||||
$client = Mockery::mock(Client::class);
|
||||
$client->shouldReceive('post')->once()->andReturn($response);
|
||||
$this->app->singleton('fcm.client', function($app) use($client) {
|
||||
return $client;
|
||||
});
|
||||
|
||||
|
||||
$fcm = new FCMSender();
|
||||
$fcm = new FCMSender($client, 'http://test.test');
|
||||
|
||||
$topics = new Topics();
|
||||
$topics->topic('test');
|
||||
|
223
vendor/brozot/laravel-fcm/tests/mocks/MockDownstreamResponse.php
vendored
Normal file
223
vendor/brozot/laravel-fcm/tests/mocks/MockDownstreamResponse.php
vendored
Normal file
@@ -0,0 +1,223 @@
|
||||
<?php namespace LaravelFCM\Mocks;
|
||||
|
||||
use LaravelFCM\Response\DownstreamResponse;
|
||||
use LaravelFCM\Response\DownstreamResponseContract;
|
||||
|
||||
/**
|
||||
* Class MockDownstreamResponse **Only use it for testing**
|
||||
*
|
||||
* @package LaravelFCM\Response
|
||||
*/
|
||||
class MockDownstreamResponse implements DownstreamResponseContract {
|
||||
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensSuccess = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var
|
||||
*/
|
||||
protected $messageId;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tokensToDelete = [];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $tokensToModify = [];
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
protected $tokensToRetry = [];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tokensWithError = [];
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var bool
|
||||
*/
|
||||
protected $hasMissingToken = false;
|
||||
|
||||
/**
|
||||
* DownstreamResponse constructor.
|
||||
*
|
||||
* @param $numberSuccess
|
||||
*/
|
||||
public function __construct($numberSuccess)
|
||||
{
|
||||
$this->numberTokensSuccess = $numberSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not using it
|
||||
*
|
||||
* @param DownstreamResponse $response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function merge(DownstreamResponse $response)
|
||||
{
|
||||
throw new \Exception('You cannot use this method for mocking response');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device reached with success + numberTokenToModify
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberSuccess()
|
||||
{
|
||||
return $this->numberTokensSuccess + count($this->tokensToModify);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device which thrown an error
|
||||
*
|
||||
* @return int
|
||||
*/public function numberFailure()
|
||||
{
|
||||
return count($this->tokensToDelete()) + count($this->tokensWithError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device that you need to modify their token
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberModification()
|
||||
{
|
||||
return count($this->tokensToModify());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to delete
|
||||
*
|
||||
* @param $token
|
||||
*/
|
||||
public function addTokenToDelete($token)
|
||||
{
|
||||
$this->tokensToDelete[] = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* get token to delete
|
||||
* remove all tokens returned by this method in your database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensToDelete()
|
||||
{
|
||||
return $this->tokensToDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to modify
|
||||
*
|
||||
* @param $oldToken
|
||||
* @param $newToken
|
||||
*/
|
||||
public function addTokenToModify($oldToken, $newToken)
|
||||
{
|
||||
$this->tokensToModify[$oldToken] = $newToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* get token to modify
|
||||
* key: oldToken
|
||||
* value: new token
|
||||
* find the old token in your database and replace it with the new one
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensToModify()
|
||||
{
|
||||
return $this->tokensToModify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to retry
|
||||
*
|
||||
* @param $token
|
||||
*/
|
||||
public function addTokenToRetry($token)
|
||||
{
|
||||
$this->tokensToRetry[] = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tokens that you should resend using exponential backoof
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensToRetry()
|
||||
{
|
||||
return $this->tokensToRetry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token to errors
|
||||
*
|
||||
* @param $token
|
||||
* @param $message
|
||||
*/
|
||||
public function addTokenWithError($token, $message)
|
||||
{
|
||||
$this->tokensWithError[$token] = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tokens that thrown an error
|
||||
* key : token
|
||||
* value : error
|
||||
* In production, remove these tokens from you database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensWithError()
|
||||
{
|
||||
return $this->tokensWithError;
|
||||
}
|
||||
|
||||
/**
|
||||
* change missing token state
|
||||
* @param $hasMissingToken
|
||||
*/
|
||||
public function setMissingToken($hasMissingToken)
|
||||
{
|
||||
$this->hasMissingToken = $hasMissingToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if missing tokens was given to the request
|
||||
* If true, remove all the empty token in your database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMissingToken()
|
||||
{
|
||||
return $this->hasMissingToken;
|
||||
}
|
||||
}
|
88
vendor/brozot/laravel-fcm/tests/mocks/MockGroupResponse.php
vendored
Normal file
88
vendor/brozot/laravel-fcm/tests/mocks/MockGroupResponse.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php namespace LaravelFCM\Mocks;
|
||||
|
||||
use LaravelFCM\Response\GroupResponseContract;
|
||||
|
||||
/**
|
||||
* Class MockGroupResponse **Only use it for testing**
|
||||
*
|
||||
* @package LaravelFCM\Response
|
||||
*/
|
||||
class MockGroupResponse implements GroupResponseContract {
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensSuccess = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var int
|
||||
*/
|
||||
protected $numberTokensFailure = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var array
|
||||
*/
|
||||
protected $tokensFailed = [];
|
||||
|
||||
/**
|
||||
* set number of success
|
||||
* @param $numberSuccess
|
||||
*/
|
||||
public function setNumberSuccess($numberSuccess)
|
||||
{
|
||||
$this->numberTokensSuccess = $numberSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device reached with success
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberSuccess()
|
||||
{
|
||||
return $this->numberTokensSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* set number of failures
|
||||
*
|
||||
* @param $numberFailures
|
||||
*/
|
||||
public function setNumberFailure($numberFailures)
|
||||
{
|
||||
$this->numberTokensSuccess = $numberFailures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of device which thrown an error
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberFailure()
|
||||
{
|
||||
return $this->numberTokensFailure;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a token to the failed list
|
||||
*
|
||||
* @param $tokenFailed
|
||||
*/
|
||||
public function addTokenFailed($tokenFailed)
|
||||
{
|
||||
$this->tokensFailed[] = $tokenFailed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all token in group that fcm cannot reach
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function tokensFailed()
|
||||
{
|
||||
return $this->tokensFailed;
|
||||
}
|
||||
}
|
86
vendor/brozot/laravel-fcm/tests/mocks/MockTopicResponse.php
vendored
Normal file
86
vendor/brozot/laravel-fcm/tests/mocks/MockTopicResponse.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php namespace LaravelFCM\Mocks;
|
||||
|
||||
use LaravelFCM\Response\TopicResponseContract;
|
||||
|
||||
/**
|
||||
* Class MockTopicResponse **Only use it for testing**
|
||||
*
|
||||
* @package LaravelFCM\Response
|
||||
*/
|
||||
class MockTopicResponse implements TopicResponseContract {
|
||||
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var string
|
||||
*/
|
||||
protected $topic;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var string
|
||||
*/
|
||||
protected $messageId;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var string
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var bool
|
||||
*/
|
||||
protected $needRetry = false;
|
||||
|
||||
/**
|
||||
* if success set a message id
|
||||
*
|
||||
* @param $messageId
|
||||
*/
|
||||
public function setSuccess($messageId)
|
||||
{
|
||||
$this->messageId = $messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* true if topic sent with success
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccess()
|
||||
{
|
||||
return (bool) $this->messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* set error
|
||||
* @param $error
|
||||
*/
|
||||
public function setError($error)
|
||||
{
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* return error message
|
||||
* you should test if it's necessary to resent it
|
||||
*
|
||||
* @return string error
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
$this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if it's necessary resent it using exponential backoff
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldRetry()
|
||||
{
|
||||
$this->error;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user