Пример #1
0
 /**
  * Test to ensure that the call to perform an action works correctly
  */
 public function testPerformActionWorksSuccessfully()
 {
     $factory = new DropletFactory();
     $data = json_decode($this->ubuntuData, true);
     $droplet = $factory->getDroplet($data['droplet']);
     $headers = ['Content-type' => 'application/json'];
     $mockRequest = $this->getMockBuilder('\\GuzzleHttp\\Message\\Request')->disableOriginalConstructor()->getMock();
     $mockAction = $this->getMock('\\Billow\\Actions\\EnableBackups', ['getRequest', 'getBody']);
     $mockAction->expects($this->once())->method('getBody')->will($this->returnValue(json_encode(['type' => 'enable_backups'])));
     $mockAction->expects($this->once())->method('getRequest')->with($headers, json_encode(['type' => 'enable_backups']))->will($this->returnValue($mockRequest));
     $this->mockClient->expects($this->once())->method('send')->with($mockRequest)->will($this->returnValue($this->mockResponse));
     $service = new DropletService();
     $service->setClient($this->mockClient);
     $response = $service->performAction($droplet, $mockAction, $headers);
     $this->assertSame($response, $this->mockResponse);
 }
Пример #2
0
 /**
  * Test to ensure that if a Request Exception is thrown that client rethrows it
  *
  * @expectedException \Exception
  */
 public function testEnsureSendExceptionIsRethrown()
 {
     $request = $this->getMockBuilder('\\GuzzleHttp\\Message\\Request')->disableOriginalConstructor()->getMock();
     $this->mockClient->expects($this->once())->method('send')->with($request)->will($this->throwException(new \Exception()));
     $client = new Client();
     $client->setHttpClient($this->mockClient);
     $client->send($request);
 }