Example #1
0
 /**
  * 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);
 }
Example #2
0
 public function it_returns_a_resource(ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, ResponseInterface $mockedResponse)
 {
     $mockedClient->createRequest(Argument::type('string'), Argument::type('string'), Argument::type('array'))->willReturn($mockedRequest);
     $mockedClient->send(Argument::any())->willReturn($mockedResponse);
     $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource');
     $mockedResponse->xml()->shouldBeCalled()->willReturn('xmlResource');
     $mockedStorage->getTokenData()->willReturn(['access_token' => 'abc', 'instance_url' => 'def', 'token_type' => 'bearer']);
     $this->request('uri', [])->shouldReturn('jsonResource');
     $this->request('uri', ['format' => 'xml'])->shouldReturn('xmlResource');
 }
Example #3
0
 public function it_should_format_header_without_compression(ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, ResponseInterface $mockedResponse)
 {
     $mockedStorage->getTokenData()->willReturn(['access_token' => 'accesstoken', 'instance_url' => 'def', 'token_type' => 'bearer']);
     $mockedClient->request('get', 'uri', ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']])->shouldBeCalled()->willReturn($mockedResponse);
     $mockedResponse->getBody()->shouldBeCalled()->willReturn($this->responseJSON);
     $responseJSON = json_decode($this->responseJSON, true);
     $this->request('uri', ['compression' => false])->shouldReturn($responseJSON);
 }
Example #4
0
 function it_should_format_header_without_compression(ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, ResponseInterface $mockedResponse)
 {
     $mockedStorage->getTokenData()->willReturn(array('access_token' => 'accesstoken', 'instance_url' => 'def', 'token_type' => 'bearer'));
     $mockedClient->createRequest("get", "uri", ['headers' => ["Authorization" => "bearer accesstoken", "Accept" => "application/json", "Content-Type" => "application/json"]])->shouldBeCalled()->willReturn($mockedRequest);
     $mockedClient->send(Argument::any())->willReturn($mockedResponse);
     $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource');
     $this->request('uri', ['compression' => false])->shouldReturn('jsonResource');
 }
Example #5
0
 public function it_should_not_call_refresh_method_if_there_is_no_token(ClientInterface $mockedClient, RequestInterface $failedRequest, StorageInterface $mockedStorage)
 {
     $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->getRefreshToken()->willThrow('\\Omniphx\\Forrest\\Exceptions\\MissingRefreshTokenException');
     $this->shouldThrow('\\Omniphx\\Forrest\\Exceptions\\MissingRefreshTokenException')->duringRequest('url', ['key' => 'value']);
 }