Esempio n. 1
0
 function it_should_refresh_the_token_if_response_throws_error(ClientInterface $mockedClient, RequestInterface $mockedRequest, SessionInterface $mockedSession, ResponseInterface $mockedResponse)
 {
     $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest);
     $mockedClient->send($mockedRequest)->willThrow('\\Omniphx\\Forrest\\Exceptions\\TokenExpiredException');
     $mockedSession->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']);
     $mockedSession->putToken(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']);
 }
Esempio n. 2
0
 function it_should_refresh(ResponseInterface $mockedResponse, SessionInterface $mockedSession)
 {
     $mockedResponse->json()->shouldBeCalled()->willReturn(['key' => 'value']);
     $mockedSession->putToken(Argument::type('array'))->shouldBeCalled();
     $this->refresh()->shouldReturn(null);
 }