Google_Http_BatchTest

Copyright 2011 Google Inc.

Defined (1)

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

/vendor/google/apiclient/tests/general/Http/BatchTest.php  
  1. class Google_Http_BatchTest extends PHPUnit_Framework_TestCase 
  2.  
  3. public function setUp() 
  4. $this->client = $this->getMockBuilder("Google_Client") 
  5. ->disableOriginalConstructor() 
  6. ->getMock(); 
  7.  
  8. public function testBasicFunctionality() 
  9. $this->client->expects($this->once()) 
  10. ->method("getBasePath") 
  11. ->will($this->returnValue("base_path")); 
  12. $batch = new Google_Http_Batch($this->client); 
  13. $this->assertAttributeEquals("base_path", "root_url", $batch); 
  14. $this->assertAttributeEquals("batch", "batch_path", $batch); 
  15.  
  16. public function testExtractionOfRootUrlFromService() 
  17. $this->client->expects($this->never()) 
  18. ->method("getBasePath"); 
  19. $service = new Google_Service($this->client); 
  20. $service->rootUrl = "root_url_dummy"; 
  21. $service->batchPath = "batch_path_dummy"; 
  22. $batch = $service->createBatch(); 
  23. $this->assertInstanceOf("Google_Http_Batch", $batch); 
  24. $this->assertAttributeEquals("root_url_dummy", "root_url", $batch); 
  25. $this->assertAttributeEquals("batch_path_dummy", "batch_path", $batch); 
  26.  
  27. public function testExecuteCustomRootUrlBatchPath() 
  28. $io = $this->getMockBuilder('Google_IO_Abstract') 
  29. ->disableOriginalConstructor() 
  30. ->setMethods(array('makeRequest', 'needsQuirk', 'executeRequest', 'setOptions', 'setTimeout', 'getTimeout')) 
  31. ->getMock(); 
  32. $req = null; 
  33. $io->expects($this->once()) 
  34. ->method("makeRequest") 
  35. ->will($this->returnCallback(function($request) use (&$req) { 
  36. $req = $request; 
  37. return $request; 
  38. })); 
  39. $this->client->expects($this->once()) 
  40. ->method("getIo") 
  41. ->will($this->returnValue($io)); 
  42. $batch = new Google_Http_Batch($this->client, false, 'https://www.example.com/', 'bat'); 
  43. $this->assertNull($batch->execute()); 
  44. $this->assertInstanceOf("Google_Http_Request", $req); 
  45. $this->assertEquals("https://www.example.com/bat", $req->getUrl()); 
  46.  
  47. public function testExecuteBodySerialization() 
  48. $io = $this->getMockBuilder('Google_IO_Abstract') 
  49. ->disableOriginalConstructor() 
  50. ->setMethods(array('makeRequest', 'needsQuirk', 'executeRequest', 'setOptions', 'setTimeout', 'getTimeout')) 
  51. ->getMock(); 
  52. $req = null; 
  53. $io->expects($this->once()) 
  54. ->method("makeRequest") 
  55. ->will($this->returnCallback(function($request) use (&$req) { 
  56. $req = $request; 
  57. return $request; 
  58. })); 
  59. $this->client->expects($this->once()) 
  60. ->method("getIo") 
  61. ->will($this->returnValue($io)); 
  62. $batch = new Google_Http_Batch($this->client, "BOUNDARY_TEXT", 'https://www.example.com/', 'bat'); 
  63. $req1 = new Google_Http_Request("https://www.example.com/req1"); 
  64. $req2 = new Google_Http_Request("https://www.example.com/req2", 'POST', array(), 'POSTBODY'); 
  65. $batch->add($req1, '1'); 
  66. $batch->add($req2, '2'); 
  67. $this->assertNull($batch->execute()); 
  68. $this->assertInstanceOf("Google_Http_Request", $req); 
  69. $format = <<<'EOF' 
  70. --BOUNDARY_TEXT 
  71. Content-Type: application/http 
  72. Content-Transfer-Encoding: binary 
  73. MIME-Version: 1.0 
  74. Content-ID: 1 
  75.  
  76. GET /req1? HTTP/1.1 
  77.  
  78.  
  79. --BOUNDARY_TEXT 
  80. Content-Type: application/http 
  81. Content-Transfer-Encoding: binary 
  82. MIME-Version: 1.0 
  83. Content-ID: 2 
  84.  
  85. POST /req2? HTTP/1.1 
  86.  
  87. POSTBODY 
  88.  
  89. --BOUNDARY_TEXT-- 
  90. EOF; 
  91. $this->assertEquals($format, $req->getPostBody()); 
  92.