key : token
value : error
In production, remove these tokens from you database
public tokensWithError ( ) : array | ||
리턴 | array |
/** * @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"]; $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, [], '{ "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"}, { "error": "MessageTooBig"} ] }'); $downstreamResponse = new DownstreamResponse($response, $tokens); $downstreamResponse1 = new DownstreamResponse($response, $tokens1); $downstreamResponse->merge($downstreamResponse1); $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()); $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->assertEquals("MessageTooBig", $downstreamResponse->tokensWithError()[$tokens[6]]); $this->assertEquals("MessageTooBig", $downstreamResponse->tokensWithError()[$tokens1[6]]); }
/** * Merge two response * * @param DownstreamResponse $response */ public function merge(DownstreamResponse $response) { $this->numberTokensSuccess += $response->numberSuccess(); $this->numberTokensFailure += $response->numberFailure(); $this->numberTokenModify += $response->numberModification(); $this->tokensToDelete = array_merge($this->tokensToDelete, $response->tokensToDelete()); $this->tokensToModify = array_merge($this->tokensToModify, $response->tokensToModify()); $this->tokensToRetry = array_merge($this->tokensToRetry, $response->tokensToRetry()); $this->tokensWithError = array_merge($this->tokensWithError, $response->tokensWithError()); }