コード例 #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
ファイル: WebServerSpec.php プロジェクト: omniphx/forrest
 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
ファイル: UserPasswordSpec.php プロジェクト: cmpas2/ayforrest
 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
ファイル: WebServerSpec.php プロジェクト: jhoff/forrest
 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
ファイル: UserPasswordSpec.php プロジェクト: omniphx/forrest
 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);
 }