ResourceTest

The Simple Calendar ResourceTest class.

Defined (1)

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

/vendor/google/apiclient/tests/general/ResourceTest.php  
  1. class ResourceTest extends PHPUnit_Framework_TestCase 
  2. private $client; 
  3. private $service; 
  4. private $logger; 
  5.  
  6. public function setUp() 
  7. $this->client = $this->getMockBuilder("Google_Client") 
  8. ->disableOriginalConstructor() 
  9. ->getMock(); 
  10. $this->logger = $this->getMockBuilder("Google_Logger_Null") 
  11. ->disableOriginalConstructor() 
  12. ->getMock(); 
  13. $this->client->expects($this->any()) 
  14. ->method("getClassConfig") 
  15. ->will($this->returnCallback(function($class, $type) { 
  16. if (!is_string($class)) { 
  17. $class = get_class($class); 
  18. $configMap = array( 
  19. "Google_Auth_Simple" => array( 
  20. "developer_key" => "testKey" 
  21. ),  
  22. ); 
  23. return isset($configMap[$class][$type]) ? $configMap[$class][$type] : null; 
  24. })); 
  25. $this->client->expects($this->any()) 
  26. ->method("getLogger") 
  27. ->will($this->returnValue($this->logger)); 
  28. $this->client->expects($this->any()) 
  29. ->method("shouldDefer") 
  30. ->will($this->returnValue(true)); 
  31. $this->client->expects($this->any()) 
  32. ->method("getBasePath") 
  33. ->will($this->returnValue("https://test.example.com")); 
  34. $this->client->expects($this->any()) 
  35. ->method("getAuth") 
  36. ->will($this->returnValue(new Google_Auth_Simple($this->client))); 
  37. $this->service = new Test_Google_Service($this->client); 
  38.  
  39. public function testCallFailure() 
  40. $resource = new Google_Service_Resource( 
  41. $this->service,  
  42. "test",  
  43. "testResource",  
  44. array("methods" =>  
  45. array( 
  46. "testMethod" => array( 
  47. "parameters" => array(),  
  48. "path" => "method/path",  
  49. "httpMethod" => "POST",  
  50. ); 
  51. $this->setExpectedException( 
  52. "Google_Exception",  
  53. "Unknown function: test->testResource->someothermethod()" 
  54. ); 
  55. $resource->call("someothermethod", array()); 
  56.  
  57. public function testCallSimple() 
  58. $resource = new Google_Service_Resource( 
  59. $this->service,  
  60. "test",  
  61. "testResource",  
  62. array("methods" =>  
  63. array( 
  64. "testMethod" => array( 
  65. "parameters" => array(),  
  66. "path" => "method/path",  
  67. "httpMethod" => "POST",  
  68. ); 
  69. $request = $resource->call("testMethod", array(array())); 
  70. $this->assertEquals("https://test.example.com/method/path?key=testKey", $request->getUrl()); 
  71. $this->assertEquals("POST", $request->getRequestMethod()); 
  72.  
  73. public function testCallServiceDefinedRoot() 
  74. $this->service->rootUrl = "https://sample.example.com"; 
  75. $resource = new Google_Service_Resource( 
  76. $this->service,  
  77. "test",  
  78. "testResource",  
  79. array("methods" =>  
  80. array( 
  81. "testMethod" => array( 
  82. "parameters" => array(),  
  83. "path" => "method/path",  
  84. "httpMethod" => "POST",  
  85. ); 
  86. $request = $resource->call("testMethod", array(array())); 
  87. $this->assertEquals("https://sample.example.com/method/path?key=testKey", $request->getUrl()); 
  88. $this->assertEquals("POST", $request->getRequestMethod());