Example #1
0
 /**
  * @test
  * @expectedException \PHPSC\PagSeguro\Client\PagSeguroException
  */
 public function handleErrorShouldRaiseExceptionWhenHostIsFromPagSeguro()
 {
     $client = new Client($this->httpClient);
     $transaction = new Transaction($this->httpClient, $this->request);
     $transaction->response = $this->response;
     $event = new Event($transaction);
     $this->request->expects($this->any())->method('getHost')->willReturn(Production::WS_HOST);
     $this->response->expects($this->any())->method('getStatusCode')->willReturn(401);
     $this->response->expects($this->any())->method('getBody')->willReturn('Unauthorized');
     $client->handleError($event);
 }
Example #2
0
 /**
  * Test to ensure that a RequestException with a response throws a droplet exception
  *
  * @expectedException \Billow\Exceptions\DropletException
  */
 public function testRequestExceptionWithResponseThrowsDropletException()
 {
     $page = 1;
     $per_page = 5;
     $headers = ['Content-type' => 'application/json'];
     $this->mockResponse->expects($this->once())->method('getBody')->will($this->returnValue('Unauthorized Request'));
     $this->mockResponse->expects($this->once())->method('getStatusCode')->will($this->returnValue(401));
     $this->mockException->expects($this->once())->method('hasResponse')->will($this->returnValue(true));
     $this->mockException->expects($this->once())->method('getResponse')->will($this->returnValue($this->mockResponse));
     $this->mockClient->expects($this->once())->method('get')->with("droplets?page={$page}&per_page={$per_page}", ['headers' => $headers])->will($this->throwException($this->mockException));
     $service = new DropletService();
     $service->setClient($this->mockClient);
     $droplets = $service->retrieveAll($headers, $per_page, $page);
 }
Example #3
0
 /**
  * Test to ensure message is able to be sent correctly
  */
 public function testEnsureMessageCanBeSent()
 {
     // Set up the data fixture
     $fh = fopen('tests/Mocking/API/Fixtures/send-data.txt', 'r');
     $response = fread($fh, 4096);
     fclose($fh);
     $channel = 'C04C8KJRC';
     $text = 'This is a test';
     $url = self::BASEURL . 'chat.postMessage';
     $bodyParam = ['body' => ['token' => $this->token, 'channel' => $channel, 'text' => $text]];
     $this->client->expects($this->once())->method('post')->with($url, $bodyParam)->will($this->returnValue($this->response));
     $this->response->expects($this->once())->method('getBody')->will($this->returnValue($response));
     $slack = new Slack($this->client, $this->token);
     $result = $slack->sendMessage($text, $channel);
     $arrayResponse = json_decode($result, true);
     $this->assertTrue($arrayResponse['ok']);
     $this->assertEquals($arrayResponse['channel'], $channel);
     $this->assertEquals($arrayResponse['message']['text'], $text);
 }