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

Commit d167923

Browse files
Added function to get the raw response from the cursor
1 parent 32eace4 commit d167923

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/cursor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ namespace arangodb { namespace fuerte { namespace php {
139139
return result;
140140
}
141141

142+
Php::Value Cursor::getResponse() {
143+
return Php::Object("ArangoDb\\Response", this->response);
144+
}
145+
142146
}}}

src/cursor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace arangodb { namespace fuerte { namespace php {
5555
void rewind();
5656

5757
Php::Value toArray();
58+
Php::Value getResponse();
5859

5960
virtual ~Cursor() = default;
6061
};

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ extern "C" {
157157
cursor.method<&arangodb::fuerte::php::Cursor::getCount>("count");
158158

159159
cursor.method<&arangodb::fuerte::php::Cursor::toArray>("toArray");
160+
cursor.method<&arangodb::fuerte::php::Cursor::getResponse>("getResponse");
160161

161162
cursor.property("ENTRY_TYPE", arangodb::fuerte::php::Cursor::ENTRY_TYPE, Php::Const);
162163
cursor.property("ENTRY_TYPE_JSON", arangodb::fuerte::php::Cursor::ENTRY_TYPE_JSON, Php::Const);

tests/ConnectionTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,61 @@ public function it_rewinds_cursor_multiple_times()
281281
$this->assertSame(200, $iterations);
282282
$this->assertTrue($dataSet1 === $dataSet2);
283283
}
284+
285+
286+
/**
287+
* @test
288+
*/
289+
public function it_gets_raw_response_from_cursor()
290+
{
291+
$this->connection = TestUtil::getConnection();
292+
293+
$cursor = $this->connection->query(Vpack::fromArray([
294+
'query' => 'FOR i IN 1..100 RETURN [i, i+1]',
295+
'batchSize' => 10
296+
]));
297+
298+
$response = $cursor->getResponse();
299+
300+
$this->assertInstanceOf(\ArangoDb\Response::class, $response);
301+
$this->assertTrue(TestUtil::wasSuccessful($response));
302+
}
303+
304+
305+
/**
306+
* @test
307+
*/
308+
public function it_rewinds_cursor_half_way_through()
309+
{
310+
$this->connection = TestUtil::getConnection();
311+
312+
$cursor = $this->connection->query(Vpack::fromArray([
313+
'query' => 'FOR i IN 1..100 RETURN [i, i+1]',
314+
'batchSize' => 10
315+
]));
316+
317+
$iterations = 0;
318+
$dataSet1 = [];
319+
$dataSet2 = [];
320+
321+
for($i = 0; $i < 50; $i++) {
322+
$cursor->valid();
323+
$dataSet1[] = $cursor->current();
324+
$cursor->next();
325+
$iterations++;
326+
}
327+
328+
$cursor->rewind();
329+
330+
while($cursor->valid()) {
331+
$dataSet2[] = $cursor->current();
332+
$cursor->next();
333+
$iterations++;
334+
}
335+
336+
$this->assertSame(150, $iterations);
337+
$this->assertCount(50, $dataSet1);
338+
$this->assertCount(100, $dataSet2);
339+
$this->assertTrue($dataSet1 === array_slice($dataSet2, 0, 50));
340+
}
284341
}

0 commit comments

Comments
 (0)