ApiBatchRequestTest

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Defined (1)

The class is defined in the following location(s).

/vendor/google/apiclient/tests/general/ApiBatchRequestTest.php  
  1. class ApiBatchRequestTest extends BaseTest 
  2. public $plus; 
  3.  
  4. public function testBatchRequestWithAuth() 
  5. if (!$this->checkToken()) { 
  6. return; 
  7. $client = $this->getClient(); 
  8. $batch = new Google_Http_Batch($client); 
  9. $this->plus = new Google_Service_Plus($client); 
  10.  
  11. $client->setUseBatch(true); 
  12. $batch->add($this->plus->people->get('me'), 'key1'); 
  13. $batch->add($this->plus->people->get('me'), 'key2'); 
  14. $batch->add($this->plus->people->get('me'), 'key3'); 
  15.  
  16. $result = $batch->execute(); 
  17. $this->assertTrue(isset($result['response-key1'])); 
  18. $this->assertTrue(isset($result['response-key2'])); 
  19. $this->assertTrue(isset($result['response-key3'])); 
  20.  
  21. public function testBatchRequest() 
  22. $client = $this->getClient(); 
  23. $batch = new Google_Http_Batch($client); 
  24. $this->plus = new Google_Service_Plus($client); 
  25.  
  26. $client->setUseBatch(true); 
  27. $batch->add($this->plus->people->get('+LarryPage'), 'key1'); 
  28. $batch->add($this->plus->people->get('+LarryPage'), 'key2'); 
  29. $batch->add($this->plus->people->get('+LarryPage'), 'key3'); 
  30.  
  31. $result = $batch->execute(); 
  32. $this->assertTrue(isset($result['response-key1'])); 
  33. $this->assertTrue(isset($result['response-key2'])); 
  34. $this->assertTrue(isset($result['response-key3'])); 
  35.  
  36. public function testInvalidBatchRequest() 
  37. $client = $this->getClient(); 
  38. $batch = new Google_Http_Batch($client); 
  39. $this->plus = new Google_Service_Plus($client); 
  40.  
  41. $client->setUseBatch(true); 
  42. $batch->add($this->plus->people->get('123456789987654321'), 'key1'); 
  43. $batch->add($this->plus->people->get('+LarryPage'), 'key2'); 
  44.  
  45. $result = $batch->execute(); 
  46. $this->assertTrue(isset($result['response-key2'])); 
  47. $this->assertInstanceOf( 
  48. 'Google_Service_Exception',  
  49. $result['response-key1'] 
  50. );