예제 #1
0
파일: Client.php 프로젝트: cmpas2/ayforrest
 /**
  * Checks to see if version is specified. If not then call storeVersion.
  * Once a version is determined, determine the available resources the
  * user has access to and store them in teh user's sesion.
  *
  * @return void
  */
 protected function storeResources()
 {
     try {
         $this->storage->get('version');
     } catch (\Exception $e) {
         $this->storeVersion();
     }
     $resources = $this->resources(['format' => 'json']);
     $this->storage->put('resources', $resources);
 }
예제 #2
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);
     //First request throws an exception
     $mockedClient->request('get', 'url', ['headers' => ['Authorization' => 'Oauth accessToken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']])->shouldBeCalled(1)->willThrow($requestException);
     $mockedStorage->get('loginURL')->shouldBeCalled()->willReturn('https://login.salesforce.com');
     $mockedStorage->getRefreshToken()->shouldBeCalled()->willReturn('refresh_token');
     $mockedClient->request('post', 'https://login.salesforce.com/services/oauth2/token', Argument::type('array'))->shouldBeCalled()->willReturn($mockedResponse);
     $mockedResponse->getBody()->shouldBeCalled()->willReturn($this->responseJSON);
     $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']);
 }
예제 #3
0
 public function it_should_return_describe(StorageInterface $mockedStorage, ResponseInterface $mockedResponse)
 {
     $mockedStorage->get('version')->shouldBeCalled()->willReturn(['url' => 'versionURL']);
     $mockedResponse->json()->shouldBeCalled()->willReturn('describe');
     $this->describe()->shouldReturn('describe');
 }
예제 #4
0
 function it_should_return_describe(StorageInterface $mockedStorage, ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest)
 {
     $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest);
     $mockedStorage->get('version')->shouldBeCalled()->willReturn(array('url' => 'versionURL'));
     $mockedResponse->json()->shouldBeCalled()->willReturn('describe');
     $this->describe()->shouldReturn('describe');
 }
예제 #5
0
 public function it_should_return_describe(ClientInterface $mockedClient, StorageInterface $mockedStorage, ResponseInterface $mockedResponse)
 {
     $mockedStorage->get('version')->shouldBeCalled()->willReturn(['url' => 'versionURL']);
     $mockedClient->request('get', 'https://na00.salesforce.comversionURL/sobjects', ['headers' => ['Authorization' => 'Oauth accessToken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']])->shouldBeCalled()->willReturn($mockedResponse);
     $mockedResponse->getBody()->shouldBeCalled()->willReturn($this->responseJSON);
     $responseJSON = json_decode($this->responseJSON, true);
     $this->describe()->shouldReturn($responseJSON);
 }