Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -3,216 +3,216 @@
use GuzzleHttp\Psr7\Response;
use LaravelFCM\Response\DownstreamResponse;
class DownstreamResponseTest extends FCMTestCase {
class DownstreamResponseTest extends FCMTestCase
{
/**
* @test
*/
public function it_construct_a_response_with_a_success()
{
$token = 'new_token';
/**
* @test
*/
public function it_construct_a_response_with_a_success()
{
$token = "new_token";
$response = new Response(200, [], "{
\"multicast_id\": 108,
\"success\": 1,
\"failure\": 0,
\"canonical_ids\": 0,
\"results\": [
{ \"message_id\": \"1:08\" }
$response = new Response(200, [], '{
"multicast_id": 108,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{ "message_id": "1:08" }
]
}");
}');
$downstreamResponse = new DownstreamResponse($response, $token);
$downstreamResponse = new DownstreamResponse($response, $token);
$this->assertEquals(1, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertEquals(1, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
/**
* @test
*/
public function it_construct_a_response_with_multiple_successes()
{
$tokens = [
"first_token",
"second_token",
"third_token"
];
/**
* @test
*/
public function it_construct_a_response_with_multiple_successes()
{
$tokens = [
'first_token',
'second_token',
'third_token',
];
$response = new Response(200, [], "{
\"multicast_id\": 108,
\"success\": 3,
\"failure\": 0,
\"canonical_ids\": 0,
\"results\": [
{ \"message_id\": \"1:01\" },
{ \"message_id\": \"1:02\" },
{ \"message_id\": \"1:03\" }
$response = new Response(200, [], '{
"multicast_id": 108,
"success": 3,
"failure": 0,
"canonical_ids": 0,
"results": [
{ "message_id": "1:01" },
{ "message_id": "1:02" },
{ "message_id": "1:03" }
]
}");
}');
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse = new DownstreamResponse($response, $tokens);
$this->assertEquals(3, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertEquals(3, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
/**
* @test
*/
public function it_construct_a_response_with_a_failure()
{
$token = "new_token";
/**
* @test
*/
public function it_construct_a_response_with_a_failure()
{
$token = 'new_token';
$response = new Response(200, [], "{
\"multicast_id\": 108,
\"success\": 0,
\"failure\": 1,
\"canonical_ids\": 0,
\"results\": [
{ \"error\": \"NotRegistered\" }
$response = new Response(200, [], '{
"multicast_id": 108,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{ "error": "NotRegistered" }
]
}");
}');
$downstreamResponse = new DownstreamResponse($response, $token);
$downstreamResponse = new DownstreamResponse($response, $token);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertFalse($downstreamResponse->hasMissingToken());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertFalse($downstreamResponse->hasMissingToken());
$this->assertCount(1, $downstreamResponse->tokensToDelete());
$this->assertEquals($token, $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
$this->assertCount(1, $downstreamResponse->tokensToDelete());
$this->assertEquals($token, $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
/**
* @test
*/
public function it_construct_a_response_with_multiple_failures()
{
$tokens = [
"first_token",
"second_token",
"third_token",
"fourth_token"
];
/**
* @test
*/
public function it_construct_a_response_with_multiple_failures()
{
$tokens = [
'first_token',
'second_token',
'third_token',
'fourth_token',
];
$response = new Response(200, [], "{
\"multicast_id\": 108,
\"success\": 0,
\"failure\": 3,
\"canonical_ids\": 0,
\"results\": [
{ \"error\": \"NotRegistered\" },
{ \"error\": \"InvalidRegistration\" },
{ \"error\": \"NotRegistered\" },
{ \"error\": \"MissingRegistration\"}
$response = new Response(200, [], '{
"multicast_id": 108,
"success": 0,
"failure": 3,
"canonical_ids": 0,
"results": [
{ "error": "NotRegistered" },
{ "error": "InvalidRegistration" },
{ "error": "NotRegistered" },
{ "error": "MissingRegistration"}
]
}");
}');
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse = new DownstreamResponse($response, $tokens);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(3, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertTrue($downstreamResponse->hasMissingToken());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(3, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertTrue($downstreamResponse->hasMissingToken());
$this->assertCount(3, $downstreamResponse->tokensToDelete());
$this->assertEquals($tokens[ 0 ], $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertEquals($tokens[ 1 ], $downstreamResponse->tokensToDelete()[ 1 ]);
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 2 ]);
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
$this->assertCount(3, $downstreamResponse->tokensToDelete());
$this->assertEquals($tokens[ 0 ], $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertEquals($tokens[ 1 ], $downstreamResponse->tokensToDelete()[ 1 ]);
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 2 ]);
$this->assertCount(0, $downstreamResponse->tokensToModify());
}
/**
* @test
*/
public function it_construct_a_response_with_a_token_to_change()
{
$token = "new_token";
/**
* @test
*/
public function it_construct_a_response_with_a_token_to_change()
{
$token = 'new_token';
$response = new Response(200, [], "{
\"multicast_id\": 108,
\"success\": 0,
\"failure\": 0,
\"canonical_ids\": 1,
\"results\": [
{ \"message_id\": \"1:2342\", \"registration_id\": \"32\" }
$response = new Response(200, [], '{
"multicast_id": 108,
"success": 0,
"failure": 0,
"canonical_ids": 1,
"results": [
{ "message_id": "1:2342", "registration_id": "32" }
]
}");
}');
$downstreamResponse = new DownstreamResponse($response, $token);
$downstreamResponse = new DownstreamResponse($response, $token);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(1, $downstreamResponse->numberModification());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(1, $downstreamResponse->numberModification());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToModify());
$this->assertTrue(array_key_exists($token, $downstreamResponse->tokensToModify()));
$this->assertEquals("32", $downstreamResponse->tokensToModify()[ $token ]);
}
$this->assertTrue(array_key_exists($token, $downstreamResponse->tokensToModify()));
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $token ]);
}
/**
* @test
*/
public function it_construct_a_response_with_multiple_tokens_to_change()
{
$tokens = [
"first_token",
"second_token",
"third_token"
];
/**
* @test
*/
public function it_construct_a_response_with_multiple_tokens_to_change()
{
$tokens = [
'first_token',
'second_token',
'third_token',
];
$response = new Response(200, [], "{
\"multicast_id\": 108,
\"success\": 0,
\"failure\": 0,
\"canonical_ids\": 3,
\"results\": [
{ \"message_id\": \"1:2342\", \"registration_id\": \"32\" },
{ \"message_id\": \"1:2342\", \"registration_id\": \"33\" },
{ \"message_id\": \"1:2342\", \"registration_id\": \"34\" }
$response = new Response(200, [], '{
"multicast_id": 108,
"success": 0,
"failure": 0,
"canonical_ids": 3,
"results": [
{ "message_id": "1:2342", "registration_id": "32" },
{ "message_id": "1:2342", "registration_id": "33" },
{ "message_id": "1:2342", "registration_id": "34" }
]
}");
}');
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse = new DownstreamResponse($response, $tokens);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(3, $downstreamResponse->numberModification());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(0, $downstreamResponse->numberFailure());
$this->assertEquals(3, $downstreamResponse->numberModification());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(3, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(3, $downstreamResponse->tokensToModify());
$this->assertTrue(array_key_exists($tokens[ 0 ], $downstreamResponse->tokensToModify()));
$this->assertEquals("32", $downstreamResponse->tokensToModify()[ $tokens[ 0 ] ]);
$this->assertTrue(array_key_exists($tokens[ 0 ], $downstreamResponse->tokensToModify()));
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $tokens[ 0 ] ]);
$this->assertTrue(array_key_exists($tokens[ 1 ], $downstreamResponse->tokensToModify()));
$this->assertEquals("33", $downstreamResponse->tokensToModify()[ $tokens[ 1 ] ]);
$this->assertTrue(array_key_exists($tokens[ 1 ], $downstreamResponse->tokensToModify()));
$this->assertEquals('33', $downstreamResponse->tokensToModify()[ $tokens[ 1 ] ]);
$this->assertTrue(array_key_exists($tokens[ 2 ], $downstreamResponse->tokensToModify()));
$this->assertEquals("34", $downstreamResponse->tokensToModify()[ $tokens[ 2 ] ]);
}
$this->assertTrue(array_key_exists($tokens[ 2 ], $downstreamResponse->tokensToModify()));
$this->assertEquals('34', $downstreamResponse->tokensToModify()[ $tokens[ 2 ] ]);
}
/**
* @test
*/
public function it_construct_a_response_with_a_token_unavailable()
{
$token = "first_token";
/**
* @test
*/
public function it_construct_a_response_with_a_token_unavailable()
{
$token = 'first_token';
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 0,
"failure": 1,
@@ -222,28 +222,28 @@ class DownstreamResponseTest extends FCMTestCase {
]
}');
$downstreamResponse = new DownstreamResponse($response, $token);
$downstreamResponse = new DownstreamResponse($response, $token);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToRetry());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToRetry());
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
}
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
}
/**
* @test
*/
public function it_construct_a_response_with_a_token_server_error()
{
$token = "first_token";
/**
* @test
*/
public function it_construct_a_response_with_a_token_server_error()
{
$token = 'first_token';
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 0,
"failure": 1,
@@ -253,28 +253,28 @@ class DownstreamResponseTest extends FCMTestCase {
]
}');
$downstreamResponse = new DownstreamResponse($response, $token);
$downstreamResponse = new DownstreamResponse($response, $token);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToRetry());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToRetry());
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
}
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
}
/**
* @test
*/
public function it_construct_a_response_with_a_token_exceeded()
{
$token = "first_token";
/**
* @test
*/
public function it_construct_a_response_with_a_token_exceeded()
{
$token = 'first_token';
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 0,
"failure": 1,
@@ -284,35 +284,35 @@ class DownstreamResponseTest extends FCMTestCase {
]
}');
$downstreamResponse = new DownstreamResponse($response, $token);
$downstreamResponse = new DownstreamResponse($response, $token);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(1, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToRetry());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToRetry());
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
}
$this->assertEquals($token, $downstreamResponse->tokensToRetry()[0]);
}
/**
* @test
*/
public function it_construct_a_response_with_a_mixed_token_to_retry()
{
$tokens = [
"first_token",
"second_token",
"third_token",
"fourth_token",
"fifth_token",
"sixth_token"
];
/**
* @test
*/
public function it_construct_a_response_with_a_mixed_token_to_retry()
{
$tokens = [
'first_token',
'second_token',
'third_token',
'fourth_token',
'fifth_token',
'sixth_token',
];
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 0,
"failure": 6,
@@ -327,41 +327,40 @@ class DownstreamResponseTest extends FCMTestCase {
]
}');
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse = new DownstreamResponse($response, $tokens);
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(6, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
$this->assertEquals(0, $downstreamResponse->numberSuccess());
$this->assertEquals(6, $downstreamResponse->numberFailure());
$this->assertEquals(0, $downstreamResponse->numberModification());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(6, $downstreamResponse->tokensToRetry());
// Unavailable is not an error caused by the token validity. it don't need to be deleted$
$this->assertCount(0, $downstreamResponse->tokensToModify());
$this->assertCount(0, $downstreamResponse->tokensToDelete());
$this->assertCount(6, $downstreamResponse->tokensToRetry());
$this->assertEquals($tokens[ 0 ], $downstreamResponse->tokensToRetry()[ 0 ]);
$this->assertEquals($tokens[ 1 ], $downstreamResponse->tokensToRetry()[ 1 ]);
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToRetry()[ 2 ]);
$this->assertEquals($tokens[ 3 ], $downstreamResponse->tokensToRetry()[ 3 ]);
$this->assertEquals($tokens[ 4 ], $downstreamResponse->tokensToRetry()[ 4 ]);
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToRetry()[ 5 ]);
$this->assertEquals($tokens[ 0 ], $downstreamResponse->tokensToRetry()[ 0 ]);
$this->assertEquals($tokens[ 1 ], $downstreamResponse->tokensToRetry()[ 1 ]);
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToRetry()[ 2 ]);
$this->assertEquals($tokens[ 3 ], $downstreamResponse->tokensToRetry()[ 3 ]);
$this->assertEquals($tokens[ 4 ], $downstreamResponse->tokensToRetry()[ 4 ]);
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToRetry()[ 5 ]);
}
}
/**
* @test
*/
public function it_construct_a_response_with_mixed_response()
{
$tokens = [
'first_token',
'second_token',
'third_token',
'fourth_token',
'fifth_token',
'sixth_token',
];
/**
* @test
*/
public function it_construct_a_response_with_mixed_response()
{
$tokens = [
"first_token",
"second_token",
"third_token",
"fourth_token",
"fifth_token",
"sixth_token"
];
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 3,
"failure": 3,
@@ -376,50 +375,49 @@ class DownstreamResponseTest extends FCMTestCase {
]
}');
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse = new DownstreamResponse($response, $tokens);
$this->assertEquals(3, $downstreamResponse->numberSuccess());
$this->assertEquals(3, $downstreamResponse->numberFailure());
$this->assertEquals(1, $downstreamResponse->numberModification());
$this->assertEquals(3, $downstreamResponse->numberSuccess());
$this->assertEquals(3, $downstreamResponse->numberFailure());
$this->assertEquals(1, $downstreamResponse->numberModification());
// Unavailable is not an error caused by the token validity. it don't need to be deleted
$this->assertCount(2, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToModify());
// Unavailable is not an error caused by the token validity. it don't need to be deleted
$this->assertCount(2, $downstreamResponse->tokensToDelete());
$this->assertCount(1, $downstreamResponse->tokensToModify());
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToDelete()[ 1 ]);
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToDelete()[ 1 ]);
$this->assertTrue(array_key_exists($tokens[ 4 ], $downstreamResponse->tokensToModify()));
$this->assertEquals("32", $downstreamResponse->tokensToModify()[ $tokens[ 4 ] ]);
}
$this->assertTrue(array_key_exists($tokens[ 4 ], $downstreamResponse->tokensToModify()));
$this->assertEquals('32', $downstreamResponse->tokensToModify()[ $tokens[ 4 ] ]);
}
/**
* @test
*/
public function it_construct_a_response_with_multiples_response()
{
/**
* @test
*/
public function it_construct_a_response_with_multiples_response()
{
$tokens = [
'first_token',
'second_token',
'third_token',
'fourth_token',
'fifth_token',
'sixth_token',
'seventh_token',
];
$tokens = [
"first_token",
"second_token",
"third_token",
"fourth_token",
"fifth_token",
"sixth_token",
"seventh_token"
];
$tokens1 = [
'first_1_token',
'second_1_token',
'third_1_token',
'fourth_1_token',
'fifth_1_token',
'sixth_1_token',
'seventh_1_token',
];
$tokens1 = [
"first_1_token",
"second_1_token",
"third_1_token",
"fourth_1_token",
"fifth_1_token",
"sixth_1_token",
"seventh_1_token"
];
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 3,
"failure": 3,
@@ -435,28 +433,28 @@ class DownstreamResponseTest extends FCMTestCase {
]
}');
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse1 = new DownstreamResponse($response, $tokens1);
$downstreamResponse = new DownstreamResponse($response, $tokens);
$downstreamResponse1 = new DownstreamResponse($response, $tokens1);
$downstreamResponse->merge($downstreamResponse1);
$downstreamResponse->merge($downstreamResponse1);
$this->assertEquals(6, $downstreamResponse->numberSuccess());
$this->assertEquals(6, $downstreamResponse->numberFailure());
$this->assertEquals(2, $downstreamResponse->numberModification());
$this->assertEquals(6, $downstreamResponse->numberSuccess());
$this->assertEquals(6, $downstreamResponse->numberFailure());
$this->assertEquals(2, $downstreamResponse->numberModification());
// Unavailable is not an error caused by the token validity. it don't need to be deleted
$this->assertCount(4, $downstreamResponse->tokensToDelete());
$this->assertCount(2, $downstreamResponse->tokensToModify());
$this->assertCount(2, $downstreamResponse->tokensWithError());
// Unavailable is not an error caused by the token validity. it don't need to be deleted
$this->assertCount(4, $downstreamResponse->tokensToDelete());
$this->assertCount(2, $downstreamResponse->tokensToModify());
$this->assertCount(2, $downstreamResponse->tokensWithError());
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertEquals($tokens1[ 2 ], $downstreamResponse->tokensToDelete()[ 2 ]);
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToDelete()[ 1 ]);
$this->assertEquals($tokens1[ 5 ], $downstreamResponse->tokensToDelete()[ 3 ]);
$this->assertEquals($tokens[ 2 ], $downstreamResponse->tokensToDelete()[ 0 ]);
$this->assertEquals($tokens1[ 2 ], $downstreamResponse->tokensToDelete()[ 2 ]);
$this->assertEquals($tokens[ 5 ], $downstreamResponse->tokensToDelete()[ 1 ]);
$this->assertEquals($tokens1[ 5 ], $downstreamResponse->tokensToDelete()[ 3 ]);
$this->assertCount(2, $downstreamResponse->tokensToRetry());
$this->assertCount(2, $downstreamResponse->tokensToRetry());
$this->assertEquals("MessageTooBig", $downstreamResponse->tokensWithError()[$tokens[6]]);
$this->assertEquals("MessageTooBig", $downstreamResponse->tokensWithError()[$tokens1[6]]);
}
}
$this->assertEquals('MessageTooBig', $downstreamResponse->tokensWithError()[$tokens[6]]);
$this->assertEquals('MessageTooBig', $downstreamResponse->tokensWithError()[$tokens1[6]]);
}
}

View File

@@ -4,14 +4,14 @@ use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use LaravelFCM\Sender\FCMSender;
class ResponseTest extends FCMTestCase {
/**
* @test
*/
public function it_send_a_notification_to_a_device()
{
$response = new Response(200, [], '{
class ResponseTest extends FCMTestCase
{
/**
* @test
*/
public function it_send_a_notification_to_a_device()
{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 3,
"failure": 3,
@@ -19,24 +19,23 @@ class ResponseTest extends FCMTestCase {
"results": [
{ "message_id": "1:0408" }
]
}' );
}');
$client = Mockery::mock(Client::class);
$client->shouldReceive('post')->once()->andReturn($response);
$client = Mockery::mock(Client::class);
$client->shouldReceive('request')->once()->andReturn($response);
$tokens = 'uniqueToken';
$tokens = 'uniqueToken';
$fcm = new FCMSender($client, 'http://test.test');
$fcm->sendTo($tokens);
}
$fcm = new FCMSender($client, 'http://test.test');
$fcm->sendTo($tokens);
}
/**
* @test
*/
public function it_send_a_notification_to_more_than_1000_devices()
{
$response = new Response(200, [], '{
/**
* @test
*/
public function it_send_a_notification_to_more_than_1000_devices()
{
$response = new Response(200, [], '{
"multicast_id": 216,
"success": 3,
"failure": 3,
@@ -49,26 +48,26 @@ class ResponseTest extends FCMTestCase {
{ "message_id": "1:2342", "registration_id": "32" },
{ "error": "NotRegistered"}
]
}' );
}');
$client = Mockery::mock(Client::class);
$client->shouldReceive('post')->times(10)->andReturn($response);
$client = Mockery::mock(Client::class);
$client->shouldReceive('request')->times(10)->andReturn($response);
$tokens = [];
for ($i=0 ; $i<10000 ; $i++) {
$tokens[$i] = 'token_'.$i;
}
$tokens = [];
for ($i = 0; $i < 10000; ++$i) {
$tokens[$i] = 'token_'.$i;
}
$fcm = new FCMSender($client, 'http://test.test');
$fcm->sendTo($tokens);
}
$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, [], '{
/**
* @test
*/
public function an_empty_array_of_tokens_thrown_an_exception()
{
$response = new Response(400, [], '{
"multicast_id": 216,
"success": 3,
"failure": 3,
@@ -81,13 +80,13 @@ class ResponseTest extends FCMTestCase {
{ "message_id": "1:2342", "registration_id": "32" },
{ "error": "NotRegistered"}
]
}' );
}');
$client = Mockery::mock(Client::class);
$client->shouldReceive('post')->once()->andReturn($response);
$client = Mockery::mock(Client::class);
$client->shouldReceive('request')->once()->andReturn($response);
$fcm = new FCMSender($client, 'http://test.test');
$this->setExpectedException(\LaravelFCM\Response\Exceptions\InvalidRequestException::class);
$fcm->sendTo([]);
}
}
$fcm = new FCMSender($client, 'http://test.test');
$this->setExpectedException(\LaravelFCM\Response\Exceptions\InvalidRequestException::class);
$fcm->sendTo([]);
}
}

View File

@@ -2,22 +2,21 @@
use Illuminate\Foundation\Testing\TestCase;
abstract class FCMTestCase extends TestCase {
abstract class FCMTestCase extends TestCase
{
public function createApplication()
{
$app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
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->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';
$app['config']['fcm.http.server_key'] = 'key=myKey';
$app['config']['fcm.http.sender_id'] = 'SENDER_ID';
$app['config']['fcm.driver'] = 'http';
$app['config']['fcm.http.timeout'] = 20;
$app['config']['fcm.http.server_send_url'] = 'http://test.test';
$app['config']['fcm.http.server_key'] = 'key=myKey';
$app['config']['fcm.http.sender_id'] = 'SENDER_ID';
return $app;
}
}
return $app;
}
}

View File

@@ -2,35 +2,35 @@
use LaravelFCM\Response\GroupResponse;
class GroupResponseTest extends FCMTestCase {
class GroupResponseTest extends FCMTestCase
{
/**
* @test
*/
public function it_construct_a_response_with_successes()
{
$notificationKey = 'notificationKey';
/**
* @test
*/
public function it_construct_a_response_with_successes()
{
$notificationKey = "notificationKey";
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
"success": 2,
"failure": 0
}');
$responseGroup = new GroupResponse($response, $notificationKey);
$responseGroup = new GroupResponse($response, $notificationKey);
$this->assertEquals(2, $responseGroup->numberSuccess());
$this->assertEquals(0, $responseGroup->numberFailure());
$this->assertCount(0, $responseGroup->tokensFailed());
}
$this->assertEquals(2, $responseGroup->numberSuccess());
$this->assertEquals(0, $responseGroup->numberFailure());
$this->assertCount(0, $responseGroup->tokensFailed());
}
/**
* @test
*/
public function it_construct_a_response_with_failures()
{
$notificationKey = "notificationKey";
/**
* @test
*/
public function it_construct_a_response_with_failures()
{
$notificationKey = 'notificationKey';
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
"success": 0,
"failure": 2,
"failed_registration_ids":[
@@ -38,24 +38,24 @@ class GroupResponseTest extends FCMTestCase {
"regId2"
]}');
$responseGroup = new GroupResponse($response, $notificationKey);
$responseGroup = new GroupResponse($response, $notificationKey);
$this->assertEquals(0, $responseGroup->numberSuccess());
$this->assertEquals(2, $responseGroup->numberFailure());
$this->assertCount(2, $responseGroup->tokensFailed());
$this->assertEquals(0, $responseGroup->numberSuccess());
$this->assertEquals(2, $responseGroup->numberFailure());
$this->assertCount(2, $responseGroup->tokensFailed());
$this->assertEquals("regId1", $responseGroup->tokensFailed()[ 0]);
$this->assertEquals("regId2", $responseGroup->tokensFailed()[ 1]);
}
$this->assertEquals('regId1', $responseGroup->tokensFailed()[ 0]);
$this->assertEquals('regId2', $responseGroup->tokensFailed()[ 1]);
}
/**
* @test
*/
public function it_construct_a_response_with_partials_failures()
{
$notificationKey = "notificationKey";
/**
* @test
*/
public function it_construct_a_response_with_partials_failures()
{
$notificationKey = 'notificationKey';
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
$response = new \GuzzleHttp\Psr7\Response(200, [], '{
"success": 1,
"failure": 2,
"failed_registration_ids":[
@@ -63,10 +63,10 @@ class GroupResponseTest extends FCMTestCase {
"regId2"
]}');
$responseGroup = new GroupResponse($response, $notificationKey);
$responseGroup = new GroupResponse($response, $notificationKey);
$this->assertEquals(1, $responseGroup->numberSuccess());
$this->assertEquals(2, $responseGroup->numberFailure());
$this->assertCount(2, $responseGroup->tokensFailed());
}
}
$this->assertEquals(1, $responseGroup->numberSuccess());
$this->assertEquals(2, $responseGroup->numberFailure());
$this->assertCount(2, $responseGroup->tokensFailed());
}
}

View File

@@ -5,19 +5,19 @@ use LaravelFCM\Message\OptionsPriorities;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;
class PayloadTest extends FCMTestCase {
/**
* @test
*/
public function it_construct_a_valid_json_with_option()
{
$targetPartial = '{
class PayloadTest extends FCMTestCase
{
/**
* @test
*/
public function it_construct_a_valid_json_with_option()
{
$targetPartial = '{
"collapse_key":"collapseKey",
"content_available":true
}';
$targetFull = '{
$targetFull = '{
"collapse_key":"collapseKey",
"content_available":true,
"priority":"high",
@@ -27,70 +27,70 @@ class PayloadTest extends FCMTestCase {
"dry_run": true
}';
$optionBuilder = new OptionsBuilder();
$optionBuilder = new OptionsBuilder();
$optionBuilder->setCollapseKey("collapseKey");
$optionBuilder->setContentAvailable(true);
$optionBuilder->setCollapseKey('collapseKey');
$optionBuilder->setContentAvailable(true);
$json = json_encode($optionBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
$optionBuilder->setPriority(OptionsPriorities::high)
->setDelayWhileIdle(true)
->setDryRun(true)
->setRestrictedPackageName("customPackageName")
->setTimeToLive(200);
$json = json_encode($optionBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
$json = json_encode($optionBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetFull, $json);
$optionBuilder->setPriority(OptionsPriorities::high)
->setDelayWhileIdle(true)
->setDryRun(true)
->setRestrictedPackageName('customPackageName')
->setTimeToLive(200);
}
$json = json_encode($optionBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetFull, $json);
}
/**
* @test
*/
public function it_construct_a_valid_json_with_data()
{
$targetAdd = '{
/**
* @test
*/
public function it_construct_a_valid_json_with_data()
{
$targetAdd = '{
"first_data":"first",
"second_data":true
}';
$targetSet = '
$targetSet = '
{
"third_data":"third",
"fourth_data":4
}';
$dataBuilder = new PayloadDataBuilder();
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData([ 'first_data' => 'first' ])
->addData([ 'second_data' => true ]);
$dataBuilder->addData(['first_data' => 'first'])
->addData(['second_data' => true]);
$json = json_encode($dataBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetAdd, $json);
$json = json_encode($dataBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetAdd, $json);
$dataBuilder->setData([ 'third_data' => 'third', 'fourth_data' => 4 ]);
$dataBuilder->setData(['third_data' => 'third', 'fourth_data' => 4]);
$json = json_encode($dataBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetSet, $json);
}
$json = json_encode($dataBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetSet, $json);
}
/**
* @test
*/
public function it_construct_a_valid_json_with_notification()
{
$targetPartial = '{
/**
* @test
*/
public function it_construct_a_valid_json_with_notification()
{
$targetPartial = '{
"title":"test_title",
"body":"test_body",
"badge":"test_badge",
"sound":"test_sound"
}';
$targetFull = '{
$targetFull = '{
"title":"test_title",
"body":"test_body",
"android_channel_id":"test_channel_id",
"badge":"test_badge",
"sound":"test_sound",
"tag":"test_tag",
@@ -103,27 +103,28 @@ class PayloadTest extends FCMTestCase {
"icon":"test_icon"
}';
$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder = new PayloadNotificationBuilder();
$notificationBuilder->setTitle('test_title')
->setBody('test_body')
->setSound('test_sound')
->setBadge('test_badge');
$notificationBuilder->setTitle('test_title')
->setBody('test_body')
->setSound('test_sound')
->setBadge('test_badge');
$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetPartial, $json);
$notificationBuilder->setTag('test_tag')
->setColor('test_color')
->setClickAction('test_click_action')
->setBodyLocationKey('test_body_key')
->setBodyLocationArgs('[ body0, body1 ]')
->setTitleLocationKey('test_title_key')
->setTitleLocationArgs('[ title0, title1 ]')
->setIcon('test_icon');
$notificationBuilder
->setChannelId('test_channel_id')
->setTag('test_tag')
->setColor('test_color')
->setClickAction('test_click_action')
->setBodyLocationKey('test_body_key')
->setBodyLocationArgs('[ body0, body1 ]')
->setTitleLocationKey('test_title_key')
->setTitleLocationArgs('[ title0, title1 ]')
->setIcon('test_icon');
$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetFull, $json);
}
}
$json = json_encode($notificationBuilder->build()->toArray());
$this->assertJsonStringEqualsJsonString($targetFull, $json);
}
}

View File

@@ -3,63 +3,62 @@
use GuzzleHttp\Psr7\Response;
use LaravelFCM\Response\TopicResponse;
class TopicsResponseTest extends FCMTestCase {
class TopicsResponseTest extends FCMTestCase
{
/**
* @test
*/
public function it_construct_a_topic_response_with_success()
{
$topic = new \LaravelFCM\Message\Topics();
$topic->topic('topicName');
/**
* @test
*/
public function it_construct_a_topic_response_with_success()
{
$topic = new \LaravelFCM\Message\Topics();
$topic->topic('topicName');
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"message_id": "1234"
}');
$topicResponse = new TopicResponse($response, $topic);
$topicResponse = new TopicResponse($response, $topic);
$this->assertTrue($topicResponse->isSuccess());
$this->assertFalse($topicResponse->shouldRetry());
$this->assertNull($topicResponse->error());
}
$this->assertTrue($topicResponse->isSuccess());
$this->assertFalse($topicResponse->shouldRetry());
$this->assertNull($topicResponse->error());
}
/**
* @test
*/
public function it_construct_a_topic_response_with_error()
{
$topic = new \LaravelFCM\Message\Topics();
$topic->topic('topicName');
/**
* @test
*/
public function it_construct_a_topic_response_with_error()
{
$topic = new \LaravelFCM\Message\Topics();
$topic->topic('topicName');
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"error": "MessageTooBig"
}');
$topicResponse = new TopicResponse($response, $topic);
$topicResponse = new TopicResponse($response, $topic);
$this->assertFalse($topicResponse->isSuccess());
$this->assertFalse($topicResponse->shouldRetry());
$this->assertEquals("MessageTooBig", $topicResponse->error());
}
$this->assertFalse($topicResponse->isSuccess());
$this->assertFalse($topicResponse->shouldRetry());
$this->assertEquals('MessageTooBig', $topicResponse->error());
}
/**
* @test
*/
public function it_construct_a_topic_response_with_error_and_it_should_retry()
{
$topic = new \LaravelFCM\Message\Topics();
$topic->topic('topicName');
/**
* @test
*/
public function it_construct_a_topic_response_with_error_and_it_should_retry()
{
$topic = new \LaravelFCM\Message\Topics();
$topic->topic('topicName');
$response = new Response(200, [], '{
$response = new Response(200, [], '{
"error": "TopicsMessageRateExceeded"
}');
$topicResponse = new TopicResponse($response, $topic);
$topicResponse = new TopicResponse($response, $topic);
$this->assertFalse($topicResponse->isSuccess());
$this->assertTrue($topicResponse->shouldRetry());
$this->assertEquals("TopicsMessageRateExceeded", $topicResponse->error());
}
}
$this->assertFalse($topicResponse->isSuccess());
$this->assertTrue($topicResponse->shouldRetry());
$this->assertEquals('TopicsMessageRateExceeded', $topicResponse->error());
}
}

View File

@@ -6,145 +6,144 @@ use LaravelFCM\Message\Topics;
use LaravelFCM\Sender\FCMSender;
use LaravelFCM\Message\Exceptions\NoTopicProvidedException;
class TopicsTest extends FCMTestCase {
class TopicsTest extends FCMTestCase
{
/**
* @test
*/
public function it_throw_an_exception_if_no_topic_is_provided()
{
$topics = new Topics();
/**
* @test
*/
public function it_throw_an_exception_if_no_topic_is_provided()
{
$topics = new Topics();
$this->setExpectedException(NoTopicProvidedException::class);
$topics->build();
}
$this->setExpectedException(NoTopicProvidedException::class);
$topics->build();
}
/**
* @test
*/
public function it_has_only_one_topic()
{
$target = '/topics/myTopic';
/**
* @test
*/
public function it_has_only_one_topic()
{
$target = "/topics/myTopic";
$topics = new Topics();
$topics = new Topics();
$topics->topic('myTopic');
$topics->topic('myTopic');
$this->assertEquals($target, $topics->build());
}
$this->assertEquals($target, $topics->build());
}
/**
* @test
*/
public function it_has_two_topics_and()
{
$target = [
'condition' => "'firstTopic' in topics && 'secondTopic' in topics",
];
/**
* @test
*/
public function it_has_two_topics_and()
{
$target = [
'condition' => "'firstTopic' in topics && 'secondTopic' in topics"
];
$topics = new Topics();
$topics = new Topics();
$topics->topic('firstTopic')->andTopic('secondTopic');
$topics->topic('firstTopic')->andTopic('secondTopic');
$this->assertEquals($target, $topics->build());
}
$this->assertEquals($target, $topics->build());
}
/**
* @test
*/
public function it_has_two_topics_or()
{
$target = [
'condition' => "'firstTopic' in topics || 'secondTopic' in topics",
];
/**
* @test
*/
public function it_has_two_topics_or()
{
$target = [
'condition' => "'firstTopic' in topics || 'secondTopic' in topics"
];
$topics = new Topics();
$topics = new Topics();
$topics->topic('firstTopic')->orTopic('secondTopic');
$topics->topic('firstTopic')->orTopic('secondTopic');
$this->assertEquals($target, $topics->build());
}
$this->assertEquals($target, $topics->build());
}
/**
* @test
*/
public function it_has_two_topics_or_and_one_and()
{
$target = [
'condition' => "'firstTopic' in topics || 'secondTopic' in topics && 'thirdTopic' in topics",
];
/**
* @test
*/
public function it_has_two_topics_or_and_one_and()
{
$target = [
'condition' => "'firstTopic' in topics || 'secondTopic' in topics && 'thirdTopic' in topics"
];
$topics = new Topics();
$topics = new Topics();
$topics->topic('firstTopic')->orTopic('secondTopic')->andTopic('thirdTopic');
$topics->topic('firstTopic')->orTopic('secondTopic')->andTopic('thirdTopic');
$this->assertEquals($target, $topics->build());
}
$this->assertEquals($target, $topics->build());
}
/**
* @test
*/
public function it_has_a_complex_topic_condition()
{
$target = [
'condition' => "'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics) || ('TopicD' in topics && 'TopicE' in topics)",
];
/**
* @test
*/
public function it_has_a_complex_topic_condition()
{
$target = [
'condition' => "'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics) || ('TopicD' in topics && 'TopicE' in topics)"
];
$topics = new Topics();
$topics = new Topics();
$topics->topic('TopicA')
->andTopic(function ($condition) {
$condition->topic('TopicB')->orTopic('TopicC');
})
->orTopic(function ($condition) {
$condition->topic('TopicD')->andTopic('TopicE');
});
$topics->topic('TopicA')
->andTopic(function($condition) {
$condition->topic('TopicB')->orTopic('TopicC');
})
->orTopic(function($condition) {
$condition->topic('TopicD')->andTopic('TopicE');
});
$this->assertEquals($target, $topics->build());
}
/**
* @test
*/
public function it_send_a_notification_to_a_topic()
{
$response = new Response(200, [], '{"message_id":6177433633397011933}');
$this->assertEquals($target, $topics->build());
}
$client = Mockery::mock(Client::class);
$client->shouldReceive('request')->once()->andReturn($response);
/**
* @test
*/
public function it_send_a_notification_to_a_topic()
{
$response = new Response(200, [], '{"message_id":6177433633397011933}' );
$fcm = new FCMSender($client, 'http://test.test');
$client = Mockery::mock(Client::class);
$client->shouldReceive('post')->once()->andReturn($response);
$topics = new Topics();
$topics->topic('test');
$fcm = new FCMSender($client, 'http://test.test');
$response = $fcm->sendToTopic($topics);
$topics = new Topics();
$topics->topic('test');
$this->assertTrue($response->isSuccess());
$this->assertFalse($response->shouldRetry());
$this->assertNull($response->error());
}
$response = $fcm->sendToTopic($topics);
/**
* @test
*/
public function it_send_a_notification_to_a_topic_and_return_error()
{
$response = new Response(200, [], '{"error":"TopicsMessageRateExceeded"}');
$this->assertTrue($response->isSuccess());
$this->assertFalse($response->shouldRetry());
$this->assertNull($response->error());
}
$client = Mockery::mock(Client::class);
$client->shouldReceive('request')->once()->andReturn($response);
/**
* @test
*/
public function it_send_a_notification_to_a_topic_and_return_error()
{
$response = new Response(200, [], '{"error":"TopicsMessageRateExceeded"}' );
$fcm = new FCMSender($client, 'http://test.test');
$client = Mockery::mock(Client::class);
$client->shouldReceive('post')->once()->andReturn($response);
$topics = new Topics();
$topics->topic('test');
$fcm = new FCMSender($client, 'http://test.test');
$response = $fcm->sendToTopic($topics);
$topics = new Topics();
$topics->topic('test');
$response = $fcm->sendToTopic($topics);
$this->assertFalse($response->isSuccess());
$this->assertTrue($response->shouldRetry());
$this->assertEquals('TopicsMessageRateExceeded', $response->error());
}
}
$this->assertFalse($response->isSuccess());
$this->assertTrue($response->shouldRetry());
$this->assertEquals('TopicsMessageRateExceeded', $response->error());
}
}

View File

@@ -1,223 +1,232 @@
<?php namespace LaravelFCM\Mocks;
<?php
namespace LaravelFCM\Mocks;
use LaravelFCM\Response\DownstreamResponse;
use LaravelFCM\Response\DownstreamResponseContract;
/**
* Class MockDownstreamResponse **Only use it for testing**
*
* @package LaravelFCM\Response
* Class MockDownstreamResponse **Only use it for testing**.
*/
class MockDownstreamResponse implements DownstreamResponseContract {
class MockDownstreamResponse implements DownstreamResponseContract
{
/**
* @internal
*
* @var int
*/
protected $numberTokensSuccess = 0;
/**
* @internal
*
* @var
*/
protected $messageId;
/**
* @internal
*
* @var int
*/
protected $numberTokensSuccess = 0;
/**
* @internal
*
* @var array
*/
protected $tokensToDelete = [];
/**
* @internal
*
* @var array
*/
protected $tokensToModify = [];
/**
* @internal
*
* @var array
*/
protected $tokensToRetry = [];
/**
* @internal
*
* @var
*/
protected $messageId;
/**
* @internal
*
* @var array
*/
protected $tokensWithError = [];
/**
* @internal
*
* @var array
*/
protected $tokensToDelete = [];
/**
* @internal
*
* @var bool
*/
protected $hasMissingToken = false;
/**
* @internal
*
* @var array
*/
/**
* DownstreamResponse constructor.
*
* @param $numberSuccess
*/
public function __construct($numberSuccess)
{
$this->numberTokensSuccess = $numberSuccess;
}
protected $tokensToModify = [];
/**
* @internal
*
* @var array
*/
/**
* Not using it.
*
* @param DownstreamResponse $response
*
* @throws \Exception
*/
public function merge(DownstreamResponse $response)
{
throw new \Exception('You cannot use this method for mocking response');
}
protected $tokensToRetry = [];
/**
* Get the number of device reached with success + numberTokenToModify.
*
* @return int
*/
public function numberSuccess()
{
return $this->numberTokensSuccess + count($this->tokensToModify);
}
/**
* @internal
*
* @var array
*/
protected $tokensWithError = [];
/**
* Get the number of device which thrown an error.
*
* @return int
*/
public function numberFailure()
{
return count($this->tokensToDelete()) + count($this->tokensWithError);
}
/**
* @internal
* @var bool
*/
protected $hasMissingToken = false;
/**
* Get the number of device that you need to modify their token.
*
* @return int
*/
public function numberModification()
{
return count($this->tokensToModify());
}
/**
* DownstreamResponse constructor.
*
* @param $numberSuccess
*/
public function __construct($numberSuccess)
{
$this->numberTokensSuccess = $numberSuccess;
}
/**
* Add a token to delete.
*
* @param $token
* @return MockDownstreamResponse
*/
public function addTokenToDelete($token)
{
$this->tokensToDelete[] = $token;
return $this;
}
/**
* 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 token to delete
* remove all tokens returned by this method in your database.
*
* @return array
*/
public function tokensToDelete()
{
return $this->tokensToDelete;
}
/**
* Get the number of device reached with success + numberTokenToModify
*
* @return int
*/
public function numberSuccess()
{
return $this->numberTokensSuccess + count($this->tokensToModify);
}
/**
* Add a token to modify.
*
* @param $oldToken
* @param $newToken
* @return MockDownstreamResponse
*/
public function addTokenToModify($oldToken, $newToken)
{
$this->tokensToModify[$oldToken] = $newToken;
return $this;
}
/**
* Get the number of device which thrown an error
*
* @return int
*/public function numberFailure()
{
return count($this->tokensToDelete()) + count($this->tokensWithError);
}
/**
* 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;
}
/**
* 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 retry.
*
* @param $token
* @return MockDownstreamResponse
*/
public function addTokenToRetry($token)
{
$this->tokensToRetry[] = $token;
return $this;
}
/**
* Add a token to delete
*
* @param $token
*/
public function addTokenToDelete($token)
{
$this->tokensToDelete[] = $token;
}
/**
* Get tokens that you should resend using exponential backoof.
*
* @return array
*/
public function tokensToRetry()
{
return $this->tokensToRetry;
}
/**
* 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 errors.
*
* @param $token
* @param $message
* @return MockDownstreamResponse
*/
public function addTokenWithError($token, $message)
{
$this->tokensWithError[$token] = $message;
return $this;
}
/**
* Add a token to modify
*
* @param $oldToken
* @param $newToken
*/
public function addTokenToModify($oldToken, $newToken)
{
$this->tokensToModify[$oldToken] = $newToken;
}
/**
* 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;
}
/**
* 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;
}
/**
* change missing token state.
*
* @param $hasMissingToken
* @return MockDownstreamResponse
*/
public function setMissingToken($hasMissingToken)
{
$this->hasMissingToken = $hasMissingToken;
return $this;
}
/**
* 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;
}
}
/**
* 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;
}
}

View File

@@ -1,88 +1,123 @@
<?php namespace LaravelFCM\Mocks;
<?php
namespace LaravelFCM\Mocks;
use LaravelFCM\Response\GroupResponseContract;
/**
* Class MockGroupResponse **Only use it for testing**
*
* @package LaravelFCM\Response
* Class MockGroupResponse **Only use it for testing**.
*/
class MockGroupResponse implements GroupResponseContract {
class MockGroupResponse implements GroupResponseContract
{
/**
* @internal
*
* @var int
*/
protected $numberTokensSuccess = 0;
/**
* @internal
* @var int
*/
protected $numberTokensSuccess = 0;
/**
* @internal
*
* @var int
*/
protected $numberTokensFailure = 0;
/**
* @internal
* @var int
*/
protected $numberTokensFailure = 0;
/**
* @internal
*
* @var array
*/
protected $tokensFailed = [];
/**
* @internal
* @var array
*/
protected $tokensFailed = [];
/**
* @internal
*
* @var string
*/
protected $to;
/**
* set number of success
* @param $numberSuccess
*/
public function setNumberSuccess($numberSuccess)
{
$this->numberTokensSuccess = $numberSuccess;
}
/**
* set number of success.
*
* @param int $numberSuccess
* @return MockGroupResponse
*/
public function setNumberSuccess($numberSuccess)
{
$this->numberTokensSuccess = $numberSuccess;
return $this;
}
/**
* Get the number of device reached with success
*
* @return int
*/
public function numberSuccess()
{
return $this->numberTokensSuccess;
}
/**
* 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;
}
/**
* set number of failures.
*
* @param $numberFailures
* @return MockGroupResponse
*/
public function setNumberFailure($numberFailures)
{
$this->numberTokensSuccess = $numberFailures;
return $this;
}
/**
* Get the number of device which thrown an error
*
* @return int
*/
public function numberFailure()
{
return $this->numberTokensFailure;
}
/**
* 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;
}
/**
* add a token to the failed list.
*
* @param $tokenFailed
* @return MockGroupResponse
*/
public function addTokenFailed($tokenFailed)
{
$this->tokensFailed[] = $tokenFailed;
return $this;
}
/**
* Get all token in group that fcm cannot reach
*
* @return array
*/
public function tokensFailed()
{
return $this->tokensFailed;
}
}
/**
* Get all token in group that fcm cannot reach.
*
* @return array
*/
public function tokensFailed()
{
return $this->tokensFailed;
}
/**
* @return string
*/
public function getTo()
{
return $this->to;
}
/**
* @param string $to
* @return MockGroupResponse
*/
public function setTo($to)
{
$this->to = $to;
return $this;
}
}

View File

@@ -1,86 +1,94 @@
<?php namespace LaravelFCM\Mocks;
<?php
namespace LaravelFCM\Mocks;
use LaravelFCM\Response\TopicResponseContract;
/**
* Class MockTopicResponse **Only use it for testing**
*
* @package LaravelFCM\Response
* Class MockTopicResponse **Only use it for testing**.
*/
class MockTopicResponse implements TopicResponseContract {
class MockTopicResponse implements TopicResponseContract
{
/**
* @internal
*
* @var string
*/
protected $topic;
/**
* @internal
*
* @var string
*/
protected $messageId;
/**
* @internal
* @var string
*/
protected $topic;
/**
* @internal
*
* @var string
*/
protected $error;
/**
* @internal
* @var string
*/
protected $messageId;
/**
* @internal
*
* @var bool
*/
protected $needRetry = false;
/**
* @internal
* @var string
*/
protected $error;
/**
* if success set a message id.
*
* @param $messageId
* @return MockTopicResponse
*/
public function setSuccess($messageId)
{
$this->messageId = $messageId;
return $this;
}
/**
* @internal
* @var bool
*/
protected $needRetry = false;
/**
* true if topic sent with success.
*
* @return bool
*/
public function isSuccess()
{
return (bool) $this->messageId;
}
/**
* if success set a message id
*
* @param $messageId
*/
public function setSuccess($messageId)
{
$this->messageId = $messageId;
}
/**
* set error.
*
* @param $error
* @return MockTopicResponse
*/
public function setError($error)
{
$this->error = $error;
return $this;
}
/**
* true if topic sent with success
*
* @return bool
*/
public function isSuccess()
{
return (bool) $this->messageId;
}
/**
* return error message
* you should test if it's necessary to resent it.
*
* @return string error
*/
public function error()
{
$this->error;
}
/**
* 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;
}
}
/**
* return true if it's necessary resent it using exponential backoff.
*
* @return bool
*/
public function shouldRetry()
{
$this->error;
}
}