This repository was archived by the owner on Jun 18, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-0
lines changed
Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -125,4 +125,16 @@ namespace arangodb { namespace fuerte { namespace php {
125125 return static_cast <int >(this ->number );
126126 }
127127
128+ Php::Value Cursor::toArray () {
129+ Php::Array result;
130+
131+ int counter = 0 ;
132+ while (this ->valid ()) {
133+ result[counter++] = this ->current ();
134+ this ->next ();
135+ }
136+
137+ return result;
138+ }
139+
128140}}}
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ namespace arangodb { namespace fuerte { namespace php {
5454 void next ();
5555 void rewind ();
5656
57+ Php::Value toArray ();
58+
5759 virtual ~Cursor () = default ;
5860 };
5961
Original file line number Diff line number Diff line change @@ -156,6 +156,8 @@ extern "C" {
156156 cursor.method <&arangodb::fuerte::php::Cursor::rewind>(" rewind" );
157157 cursor.method <&arangodb::fuerte::php::Cursor::getCount>(" count" );
158158
159+ cursor.method <&arangodb::fuerte::php::Cursor::toArray>(" toArray" );
160+
159161 cursor.property (" ENTRY_TYPE" , arangodb::fuerte::php::Cursor::ENTRY_TYPE, Php::Const);
160162 cursor.property (" ENTRY_TYPE_JSON" , arangodb::fuerte::php::Cursor::ENTRY_TYPE_JSON, Php::Const);
161163 cursor.property (" ENTRY_TYPE_ARRAY" , arangodb::fuerte::php::Cursor::ENTRY_TYPE_ARRAY, Php::Const);
Original file line number Diff line number Diff line change @@ -225,4 +225,25 @@ public function it_sends_query_and_returns_result_as_array()
225225
226226 $ this ->assertSame (100 , $ iterations );
227227 }
228+
229+ /**
230+ * @test
231+ */
232+ public function it_creates_array_from_cursor ()
233+ {
234+ $ this ->connection = TestUtil::getConnection ();
235+
236+ $ cursor = $ this ->connection ->query (
237+ Vpack::fromArray ([
238+ 'query ' => 'FOR i IN 1..100 RETURN [i, i+1] ' ,
239+ 'batchSize ' => 10
240+ ]), [
241+ Cursor::ENTRY_TYPE => Cursor::ENTRY_TYPE_ARRAY
242+ ]
243+ );
244+
245+ $ data = $ cursor ->toArray ();
246+
247+ $ this ->assertCount (100 , $ data );
248+ }
228249}
You can’t perform that action at this time.
0 commit comments