예제 #1
0
 public function it_should_authenticate(ResponseInterface $mockedResponse, RequestInterface $mockedRequest, ClientInterface $mockedClient, StorageInterface $mockedStorage)
 {
     $mockedClient->request('post', 'url/services/oauth2/token', ['form_params' => ['grant_type' => 'password', 'client_id' => 'testingClientId', 'client_secret' => 'testingClientSecret', 'username' => '*****@*****.**', 'password' => 'mypassword']])->shouldBeCalled(1)->willReturn($mockedResponse);
     $mockedResponse->getBody()->shouldBeCalled()->willReturn($this->authenticationJSON);
     $mockedStorage->putTokenData(Argument::any())->shouldBeCalled(1);
     $mockedClient->request('get', 'https://na00.salesforce.comresourceURLs', ['headers' => ['Authorization' => 'Oauth accessToken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']])->shouldBeCalled(1)->willReturn($mockedResponse);
     $this->authenticate('url')->shouldReturn(null);
 }
예제 #2
0
 function it_should_refresh_the_token_if_response_throws_error(ClientInterface $mockedClient, RequestInterface $mockedRequest, StorageInterface $mockedStorage, ResponseInterface $mockedResponse)
 {
     $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest);
     $mockedClient->send($mockedRequest)->willThrow('\\Omniphx\\Forrest\\Exceptions\\TokenExpiredException');
     $mockedStorage->getRefreshToken()->shouldBeCalled()->willReturn('refresh_token');
     $mockedClient->post('https://login.salesforce.com/services/oauth2/token', Argument::type('array'))->shouldBeCalled()->willReturn($mockedResponse);
     $mockedResponse->json()->shouldBeCalled(1)->willReturn(['key' => 'value']);
     $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled();
     //This might seem counter-intuitive. We are throwing an exception with the send() method, but we can't stop it. Since we are calling the send() method twice, the behavior is correct for it to throw an exception. Actual behavior would never throw the exception, it would return a response.
     $this->shouldThrow('\\Omniphx\\Forrest\\Exceptions\\TokenExpiredException')->duringRequest('url', ['key' => 'value']);
 }
예제 #3
0
 public function it_should_refresh_the_token_if_response_throws_error(ClientInterface $mockedClient, RequestInterface $mockedRequest, StorageInterface $mockedStorage, ResponseInterface $mockedResponse)
 {
     //Testing that we catch 401 errors and refresh the salesforce token.
     $failedRequest = new Request('GET', 'fakeurl');
     $failedResponse = new Response(401);
     $requestException = new RequestException('Salesforce token has expired', $failedRequest, $failedResponse);
     $mockedClient->send($mockedRequest)->willThrow($requestException);
     $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest);
     $mockedStorage->getRefreshToken()->shouldBeCalled()->willReturn('refresh_token');
     $mockedClient->post('https://login.salesforce.com/services/oauth2/token', Argument::type('array'))->shouldBeCalled()->willReturn($mockedResponse);
     $mockedResponse->json()->shouldBeCalled(1)->willReturn(['key' => 'value']);
     $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled();
     //This might seem counter-intuitive. We are throwing an exception with the send() method, but we can't stop it. Basically creating an infinite loop of the token being expired. What we can do is verify the methods in the refresh() method are being fired.
     $tokenException = new TokenExpiredException('Salesforce token has expired', $requestException);
     $this->shouldThrow($tokenException)->duringRequest('url', ['key' => 'value']);
 }
예제 #4
0
 public function it_should_refresh(ResponseInterface $mockedResponse, StorageInterface $mockedStorage)
 {
     $mockedResponse->json()->shouldBeCalled()->willReturn(['key' => 'value']);
     $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled();
     $this->refresh()->shouldReturn(null);
 }