ApiBatchRequestTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. class ApiBatchRequestTest extends BaseTest
  21. {
  22. public $plus;
  23. public function testBatchRequestWithAuth()
  24. {
  25. if (!$this->checkToken()) {
  26. return;
  27. }
  28. $client = $this->getClient();
  29. $batch = new Google_Http_Batch($client);
  30. $this->plus = new Google_Service_Plus($client);
  31. $client->setUseBatch(true);
  32. $batch->add($this->plus->people->get('me'), 'key1');
  33. $batch->add($this->plus->people->get('me'), 'key2');
  34. $batch->add($this->plus->people->get('me'), 'key3');
  35. $result = $batch->execute();
  36. $this->assertTrue(isset($result['response-key1']));
  37. $this->assertTrue(isset($result['response-key2']));
  38. $this->assertTrue(isset($result['response-key3']));
  39. }
  40. public function testBatchRequest()
  41. {
  42. $client = $this->getClient();
  43. $batch = new Google_Http_Batch($client);
  44. $this->plus = new Google_Service_Plus($client);
  45. $client->setUseBatch(true);
  46. $batch->add($this->plus->people->get('+LarryPage'), 'key1');
  47. $batch->add($this->plus->people->get('+LarryPage'), 'key2');
  48. $batch->add($this->plus->people->get('+LarryPage'), 'key3');
  49. $result = $batch->execute();
  50. $this->assertTrue(isset($result['response-key1']));
  51. $this->assertTrue(isset($result['response-key2']));
  52. $this->assertTrue(isset($result['response-key3']));
  53. }
  54. public function testInvalidBatchRequest()
  55. {
  56. $client = $this->getClient();
  57. $batch = new Google_Http_Batch($client);
  58. $this->plus = new Google_Service_Plus($client);
  59. $client->setUseBatch(true);
  60. $batch->add($this->plus->people->get('123456789987654321'), 'key1');
  61. $batch->add($this->plus->people->get('+LarryPage'), 'key2');
  62. $result = $batch->execute();
  63. $this->assertTrue(isset($result['response-key2']));
  64. $this->assertInstanceOf(
  65. 'Google_Service_Exception',
  66. $result['response-key1']
  67. );
  68. }
  69. }