public function testOnFailureWhichSuccessOnThirdTime()
 {
     $client = $this->createClient([RequestOptions::AUTH => 'oauth2', RequestOptions::HTTP_ERRORS => false], [MockOAuth2Server::KEY_TOKEN_INVALID_COUNT => 2, MockOAuth2Server::KEY_EXPECTED_QUERY_COUNT => 4]);
     $credentials = ['client_id' => 'test', 'client_secret' => 'testSecret'];
     $accessTokenGrantType = new ClientCredentials($client, $credentials);
     $middleware = new OAuthMiddleware($client, $accessTokenGrantType);
     $handlerStack = $this->getHandlerStack();
     $handlerStack->push($middleware->onBefore());
     $handlerStack->push($middleware->onFailure(5));
     // Will invoke 2 times onFailure
     $response = $client->get('/api/collection');
     $this->assertEquals(200, $response->getStatusCode());
 }