Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit ec256f3

Browse files
committed
Remove vpack argument from HTTP methods where it is not allowed (close #35)
1 parent ff67a6f commit ec256f3

File tree

7 files changed

+52
-16
lines changed

7 files changed

+52
-16
lines changed

phpstorm-stubs/arangodb/arangodb.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,19 @@ public function connect(): void
6565
* Sends a HTTP DELETE request
6666
*
6767
* @param string $path URI path of ArangoDB Rest API
68-
* @param Vpack $vpack Request data
6968
* @param array $queryParams Map of query params, added to URI path
7069
*/
71-
public function delete(string $path, Vpack $vpack, array $queryParams = null): Response
70+
public function delete(string $path, array $queryParams = null): Response
7271
{
7372
}
7473

7574
/**
7675
* Sends a HTTP GET request
7776
*
7877
* @param string $path URI path of ArangoDB Rest API
79-
* @param Vpack $vpack Request data
8078
* @param array|null $queryParams Map of query params added to URI path
8179
*/
82-
public function get(string $path, Vpack $vpack, array $queryParams = null): Response
80+
public function get(string $path, array $queryParams = null): Response
8381
{
8482
}
8583

@@ -109,10 +107,9 @@ public function put(string $path, Vpack $vpack, array $queryParams = null): Resp
109107
* Sends a HTTP HEAD request
110108
*
111109
* @param string $path URI path of ArangoDB Rest API
112-
* @param Vpack $vpack Request data
113110
* @param array|null $queryParams Map of query params added to URI path
114111
*/
115-
public function head(string $path, Vpack $vpack, array $queryParams = null): Response
112+
public function head(string $path, array $queryParams = null): Response
116113
{
117114
}
118115

@@ -131,10 +128,9 @@ public function patch(string $path, Vpack $vpack, array $queryParams = null): Re
131128
* Sends a HTTP OPTIONS request
132129
*
133130
* @param string $path URI path of ArangoDB Rest API
134-
* @param Vpack $vpack Request data
135131
* @param array|null $queryParams Map of query params added to URI path
136132
*/
137-
public function options(string $path, Vpack $vpack, array $queryParams = null): Response
133+
public function options(string $path, array $queryParams = null): Response
138134
{
139135
}
140136

src/connection.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ namespace arangodb { namespace fuerte { namespace php {
182182

183183
Php::Value Connection::methodDelete(Php::Parameters &params)
184184
{
185-
Request request(params);
185+
Request request(params[0], params[1]);
186186
request.setHttpMethod(Request::METHOD_DELETE);
187187

188188
return Php::Object("ArangoDb\\Response", this->sendRequest(&request));
189189
}
190190

191191
Php::Value Connection::methodGet(Php::Parameters &params)
192192
{
193-
Request request(params);
193+
Request request(params[0], params[1]);
194194
request.setHttpMethod(Request::METHOD_GET);
195195

196196
return Php::Object("ArangoDb\\Response", this->sendRequest(&request));
@@ -214,7 +214,7 @@ namespace arangodb { namespace fuerte { namespace php {
214214

215215
Php::Value Connection::methodHead(Php::Parameters &params)
216216
{
217-
Request request(params);
217+
Request request(params[0], params[1]);
218218
request.setHttpMethod(Request::METHOD_HEAD);
219219

220220
return Php::Object("ArangoDb\\Response", this->sendRequest(&request));
@@ -230,7 +230,7 @@ namespace arangodb { namespace fuerte { namespace php {
230230

231231
Php::Value Connection::methodOptions(Php::Parameters &params)
232232
{
233-
Request request(params);
233+
Request request(params[0], params[1]);
234234
request.setHttpMethod(Request::METHOD_OPTIONS);
235235

236236
return Php::Object("ArangoDb\\Response", this->sendRequest(&request));

src/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,21 @@ extern "C" {
6565
});
6666

6767
Php::Arguments methodArgs = {
68+
Php::ByVal("path", Php::Type::String, true),
69+
Php::ByVal("queryParams", Php::Type::Array, false)
70+
};
71+
Php::Arguments methodArgsPayload = {
6872
Php::ByVal("path", Php::Type::String, true),
6973
Php::ByVal("vpack", "ArangoDb\\Vpack", true),
7074
Php::ByVal("queryParams", Php::Type::Array, false)
7175
};
7276

7377
connection.method<&arangodb::fuerte::php::Connection::methodDelete>("delete", methodArgs);
7478
connection.method<&arangodb::fuerte::php::Connection::methodGet>("get", methodArgs);
75-
connection.method<&arangodb::fuerte::php::Connection::methodPost>("post", methodArgs);
76-
connection.method<&arangodb::fuerte::php::Connection::methodPut>("put", methodArgs);
79+
connection.method<&arangodb::fuerte::php::Connection::methodPost>("post", methodArgsPayload);
80+
connection.method<&arangodb::fuerte::php::Connection::methodPut>("put", methodArgsPayload);
7781
connection.method<&arangodb::fuerte::php::Connection::methodHead>("head", methodArgs);
78-
connection.method<&arangodb::fuerte::php::Connection::methodPatch>("patch", methodArgs);
82+
connection.method<&arangodb::fuerte::php::Connection::methodPatch>("patch", methodArgsPayload);
7983
connection.method<&arangodb::fuerte::php::Connection::methodOptions>("options", methodArgs);
8084

8185
connection.method<&arangodb::fuerte::php::Connection::wait>("wait");

src/request.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ namespace arangodb { namespace fuerte { namespace php {
1010
{
1111
}
1212

13+
Request::Request(std::string path, std::map<std::string, std::string> queryParams): path(path), queryParams(queryParams)
14+
{
15+
}
16+
1317
Request::Request()
1418
{
1519
}

src/request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace arangodb { namespace fuerte { namespace php {
3333

3434
Request(Php::Parameters params);
3535
Request(std::string path, const Vpack* vpack);
36+
Request(string path, map<string, string> queryParams);
3637
Request(std::string path, const Vpack* vpack, std::map<std::string, std::string> queryParams);
3738
Request();
3839

tests/ConnectionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,35 @@ public function it_throws_request_failed_exception_with_response_data()
184184
$this->assertSame('duplicate name', $e->getMessage());
185185
}
186186
}
187+
188+
/**
189+
* @test
190+
*/
191+
public function it_sends_get_request_without_params()
192+
{
193+
$this->connection = TestUtil::getConnection();
194+
195+
$response = $this->connection->get('/_api/version');
196+
197+
$body = json_decode($response->getBody(), true);
198+
199+
$this->assertNotNull($body);
200+
$this->assertSame("arango", $body['server']);
201+
}
202+
203+
/**
204+
* @test
205+
*/
206+
public function it_sends_get_request_with_params()
207+
{
208+
$this->connection = TestUtil::getConnection();
209+
210+
$response = $this->connection->get('/_admin/log', ['size' => 2]);
211+
212+
$body = json_decode($response->getBody(), true);
213+
214+
$this->assertNotNull($body);
215+
$this->assertTrue($body['totalAmount'] > 3);
216+
$this->assertCount(2, $body['lid']);
217+
}
187218
}

tests/TestUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function getConnectionParams(): array
4040
public static function deleteCollection(Connection $connection, string $collection): void
4141
{
4242
try {
43-
$connection->delete('/_api/collection/' . $collection, Vpack::fromArray([]));
43+
$connection->delete('/_api/collection/' . $collection);
4444
} catch (\Throwable $e) {
4545
// needed if test deletes collection
4646
}

0 commit comments

Comments
 (0)