PluginProbe
Authorizer / 2.6.7
Authorizer v2.6.7
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / vendor / google-api-php-client / tests / general / ResourceTest.php

ResourceTest.php in Authorizer 2.6.7, at vendor/google-api-php-client/tests/general/ResourceTest.php

141 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
21 class Test_Google_Service extends Google_Service
22 {
23 public function __construct(Google_Client $client)
24 {
25 parent::__construct($client);
26 $this->rootUrl = "";
27 $this->servicePath = "";
28 $this->version = "v1beta1";
29 $this->serviceName = "test";
30 }
31 }
32
33 class ResourceTest extends PHPUnit_Framework_TestCase
34 {
35 private $client;
36 private $service;
37 private $logger;
38
39 public function setUp()
40 {
41 $this->client = $this->getMockBuilder("Google_Client")
42 ->disableOriginalConstructor()
43 ->getMock();
44 $this->logger = $this->getMockBuilder("Google_Logger_Null")
45 ->disableOriginalConstructor()
46 ->getMock();
47 $this->client->expects($this->any())
48 ->method("getClassConfig")
49 ->will($this->returnCallback(function($class, $type) {
50 if (!is_string($class)) {
51 $class = get_class($class);
52 }
53 $configMap = array(
54 "Google_Auth_Simple" => array(
55 "developer_key" => "testKey"
56 ),
57 );
58 return isset($configMap[$class][$type]) ? $configMap[$class][$type] : null;
59 }));
60 $this->client->expects($this->any())
61 ->method("getLogger")
62 ->will($this->returnValue($this->logger));
63 $this->client->expects($this->any())
64 ->method("shouldDefer")
65 ->will($this->returnValue(true));
66 $this->client->expects($this->any())
67 ->method("getBasePath")
68 ->will($this->returnValue("https://test.example.com"));
69 $this->client->expects($this->any())
70 ->method("getAuth")
71 ->will($this->returnValue(new Google_Auth_Simple($this->client)));
72 $this->service = new Test_Google_Service($this->client);
73 }
74
75 public function testCallFailure()
76 {
77 $resource = new Google_Service_Resource(
78 $this->service,
79 "test",
80 "testResource",
81 array("methods" =>
82 array(
83 "testMethod" => array(
84 "parameters" => array(),
85 "path" => "method/path",
86 "httpMethod" => "POST",
87 )
88 )
89 )
90 );
91 $this->setExpectedException(
92 "Google_Exception",
93 "Unknown function: test->testResource->someothermethod()"
94 );
95 $resource->call("someothermethod", array());
96 }
97
98 public function testCallSimple()
99 {
100 $resource = new Google_Service_Resource(
101 $this->service,
102 "test",
103 "testResource",
104 array("methods" =>
105 array(
106 "testMethod" => array(
107 "parameters" => array(),
108 "path" => "method/path",
109 "httpMethod" => "POST",
110 )
111 )
112 )
113 );
114 $request = $resource->call("testMethod", array(array()));
115 $this->assertEquals("https://test.example.com/method/path?key=testKey", $request->getUrl());
116 $this->assertEquals("POST", $request->getRequestMethod());
117 }
118
119 public function testCallServiceDefinedRoot()
120 {
121 $this->service->rootUrl = "https://sample.example.com";
122 $resource = new Google_Service_Resource(
123 $this->service,
124 "test",
125 "testResource",
126 array("methods" =>
127 array(
128 "testMethod" => array(
129 "parameters" => array(),
130 "path" => "method/path",
131 "httpMethod" => "POST",
132 )
133 )
134 )
135 );
136 $request = $resource->call("testMethod", array(array()));
137 $this->assertEquals("https://sample.example.com/method/path?key=testKey", $request->getUrl());
138 $this->assertEquals("POST", $request->getRequestMethod());
139 }
140 }
141