2727use Laudis \Neo4j \Exception \Neo4jException ;
2828use Laudis \Neo4j \Formatter \SummarizedResultFormatter ;
2929use Laudis \Neo4j \ParameterHelper ;
30+ use Laudis \Neo4j \Types \CypherList ;
3031use Laudis \Neo4j \Types \CypherMap ;
32+ use Laudis \Neo4j \Types \Node ;
3133use function str_starts_with ;
3234
3335/**
@@ -76,7 +78,7 @@ public function testValidListParameterHelper(string $alias): void
7678RETURN $listOrMap AS x
7779CYPHER, ['listOrMap ' => ParameterHelper::asList ([1 , 2 , 3 ])], $ alias );
7880 self ::assertEquals (1 , $ result ->count ());
79- self ::assertEquals ([1 , 2 , 3 ], $ result ->first ()->get ('x ' ));
81+ self ::assertEquals (new CypherList ( [1 , 2 , 3 ]) , $ result ->first ()->get ('x ' ));
8082 }
8183
8284 /**
@@ -102,7 +104,7 @@ public function testValidMapParameterHelper(string $alias): void
102104RETURN $listOrMap AS x
103105CYPHER, ['listOrMap ' => ParameterHelper::asMap (['a ' => 'b ' , 'c ' => 'd ' ])], $ alias );
104106 self ::assertEquals (1 , $ result ->count ());
105- self ::assertEquals (['a ' => 'b ' , 'c ' => 'd ' ], $ result ->first ()->get ('x ' ));
107+ self ::assertEquals (new CypherMap ( ['a ' => 'b ' , 'c ' => 'd ' ]) , $ result ->first ()->get ('x ' ));
106108 }
107109
108110 /**
@@ -164,14 +166,18 @@ public function testCreationAndResult(string $alias): void
164166CYPHER
165167 , ['x ' => 'x ' ], $ alias )->first ();
166168
167- self ::assertEquals (['x ' => 'x ' ], $ result ->get ('x ' ));
169+ self ::assertEquals (['x ' => 'x ' ], $ result ->getAsNode ('x ' )-> getProperties ()-> toArray ( ));
168170 }
169171
170172 /**
171173 * @dataProvider connectionAliases
172174 */
173175 public function testPath (string $ alias ): void
174176 {
177+ if (str_starts_with ($ alias , 'http ' )) {
178+ self ::markTestSkipped ('Http cannot detected nested attributes ' );
179+ }
180+
175181 $ results = $ this ->getClient ()->run (<<<'CYPHER'
176182MERGE (b:Node {x:$x}) - [:HasNode {attribute: $xy}] -> (:Node {y:$y}) - [:HasNode {attribute: $yz}] -> (:Node {z:$z})
177183WITH b
@@ -183,9 +189,20 @@ public function testPath(string $alias): void
183189 self ::assertEquals (1 , $ results ->count ());
184190 $ result = $ results ->first ();
185191 self ::assertEquals (3 , $ result ->count ());
186- self ::assertEquals (['x ' => 'x ' ], $ result ->get ('x ' ));
187- self ::assertEquals ([['attribute ' => 'xy ' ], ['attribute ' => 'yz ' ]], $ result ->get ('y ' ));
188- self ::assertEquals (['z ' => 'z ' ], $ result ->get ('z ' ));
192+ self ::assertEquals (['x ' => 'x ' ], $ result ->getAsNode ('x ' )->getProperties ()->toArray ());
193+ self ::assertEquals (
194+ [['attribute ' => 'xy ' ], ['attribute ' => 'yz ' ]],
195+ /** @psalm-suppress MissingClosureReturnType */
196+ $ result ->getAsCypherList ('y ' )->map (static function ($ r ) {
197+ /**
198+ * @psalm-suppress MixedMethodCall
199+ *
200+ * @var array <string, string>
201+ */
202+ return $ r ->getProperties ()->toArray ();
203+ })->toArray ()
204+ );
205+ self ::assertEquals (['z ' => 'z ' ], $ result ->getAsNode ('z ' )->getProperties ()->toArray ());
189206 }
190207
191208 /**
@@ -202,8 +219,8 @@ public function testNullListAndMap(string $alias): void
202219 $ result = $ results ->first ();
203220 self ::assertEquals (3 , $ result ->count ());
204221 self ::assertNull ($ result ->get ('x ' ));
205- self ::assertEquals ([1 , 2 , 3 ], $ result ->get ('y ' ));
206- self ::assertEquals (['x ' => 'x ' , 'y ' => 'y ' , 'z ' => 'z ' ], $ result ->get ('z ' ));
222+ self ::assertEquals ([1 , 2 , 3 ], $ result ->getAsMap ('y ' )-> toArray ( ));
223+ self ::assertEquals (['x ' => 'x ' , 'y ' => 'y ' , 'z ' => 'z ' ], $ result ->getAsMap ('z ' )-> toArray ( ));
207224 }
208225
209226 /**
@@ -223,8 +240,8 @@ public function testListAndMapInput(string $alias): void
223240 self ::assertEquals (1 , $ results ->count ());
224241 $ result = $ results ->first ();
225242 self ::assertEquals (2 , $ result ->count ());
226- self ::assertEquals (['x ' => 'x ' ], $ result ->get ('x ' ));
227- self ::assertEquals (['list ' => [1 , 2 , 3 ]] , $ result ->get ('y ' ));
243+ self ::assertEquals (new CypherMap ( ['x ' => 'x ' ]) , $ result ->getAsNode ('x ' )-> getProperties ( ));
244+ self ::assertEquals (new CypherMap ( ['list ' => new CypherList ( [1 , 2 , 3 ])]) , $ result ->getAsNode ('y ' )-> getProperties ( ));
228245 }
229246
230247 /**
@@ -250,11 +267,12 @@ public function testPathReturnType(string $alias): void
250267 self ::assertEquals (1 , $ result ->count ());
251268 self ::assertEquals ([
252269 ['x ' => 'x ' ],
253- [],
254270 ['x ' => 'y ' ],
255- [],
256271 ['x ' => 'z ' ],
257- ], $ result ->get ('p ' ));
272+ ], $ result ->getAsPath ('p ' )->getNodes ()->map (static function (Node $ x ) {
273+ /** @var array<string, string> */
274+ return $ x ->getProperties ()->toArray ();
275+ })->toArray ());
258276 }
259277
260278 /**
@@ -305,58 +323,62 @@ public function testPeriodicCommitFail(string $alias): void
305323 */
306324 public function testLongQueryFunction (string $ alias ): void
307325 {
308- $ this ->getClient ()->writeTransaction (static function (TransactionInterface $ tsx ) {
309- $ tsx ->run ('UNWIND range(1, 10000) AS x MERGE (:Number {value: x}) ' );
310- }, $ alias , TransactionConfiguration::default ()->withTimeout (100000 ));
311- self ::assertTrue (true );
326+ self ::markTestSkipped ('Async needs to be implemented before timeout is supported ' );
327+ // $this->getClient()->writeTransaction(static function (TransactionInterface $tsx) {
328+ // $tsx->run('CALL apoc.util.sleep(10000)');
329+ // }, $alias, TransactionConfiguration::default()->withTimeout(100000));
330+ // self::assertTrue(true);
312331 }
313332
314333 /**
315334 * @dataProvider connectionAliases
316335 */
317336 public function testLongQueryFunctionNegative (string $ alias ): void
318337 {
319- if ( str_starts_with ( $ alias , ' http ' )) {
320- self :: markTestSkipped ( ' HTTP does not support tsx timeout at the moment. ' );
321- }
322-
323- $ this ->expectException (ConnectException::class);
324- $ this ->getClient ()->writeTransaction (static function (TransactionInterface $ tsx ) {
325- $ tsx ->run ('UNWIND range(1, 10000) AS x MERGE (:Number {value: x} ) ' );
326- }, $ alias , TransactionConfiguration::default ()->withTimeout (1 ));
338+ self :: markTestSkipped ( ' Async needs to be implemented before timeout is supported ' );
339+ // if (str_starts_with($alias, 'http')) {
340+ // self::markTestSkipped('Transaction timeout only work when async mode is implemented');
341+ // }
342+ // $this->expectException(ConnectException::class);
343+ // $this->getClient()->writeTransaction(static function (TransactionInterface $tsx) {
344+ // $tsx->run('CALL apoc.util.sleep( 10000)');
345+ // }, $alias, TransactionConfiguration::default()->withTimeout(1));
327346 }
328347
329348 /**
330349 * @dataProvider connectionAliases
331350 */
332351 public function testLongQueryUnmanaged (string $ alias ): void
333352 {
334- $ tsx = $ this ->getClient ()->beginTransaction ([], $ alias , TransactionConfiguration::default ()->withTimeout (100000 ));
335- $ tsx ->run ('UNWIND range(1, 10000) AS x MERGE (:Number {value: x}) ' );
336- self ::assertTrue (true );
353+ self ::markTestSkipped ('Async needs to be implemented before timeout is supported ' );
354+ // $tsx = $this->getClient()->beginTransaction([], $alias, TransactionConfiguration::default()->withTimeout(100000));
355+ // $tsx->run('UNWIND range(1, 10000) AS x MERGE (:Number {value: x})');
356+ // self::assertTrue(true);
337357 }
338358
339359 /**
340360 * @dataProvider connectionAliases
341361 */
342362 public function testLongQueryAuto (string $ alias ): void
343363 {
344- $ tsx = $ this ->getClient ()->beginTransaction ([], $ alias , TransactionConfiguration::default ()->withTimeout (100000 ));
345- $ tsx ->run ('UNWIND range(1, 10000) AS x MERGE (:Number {value: x}) ' );
346- self ::assertTrue (true );
364+ self ::markTestSkipped ('Async needs to be implemented before timeout is supported ' );
365+ // $tsx = $this->getClient()->beginTransaction([], $alias, TransactionConfiguration::default()->withTimeout(100000));
366+ // $tsx->run('UNWIND range(1, 10000) AS x MERGE (:Number {value: x})');
367+ // self::assertTrue(true);
347368 }
348369
349370 /**
350371 * @dataProvider connectionAliases
351372 */
352373 public function testLongQueryUnmanagedNegative (string $ alias ): void
353374 {
354- if (str_starts_with ($ alias , 'http ' )) {
355- self ::markTestSkipped ('HTTP does not support tsx timeout at the moment. ' );
356- }
357-
358- $ this ->expectException (ConnectException::class);
359- $ tsx = $ this ->getClient ()->beginTransaction ([], $ alias , TransactionConfiguration::default ()->withTimeout (1 ));
360- $ tsx ->run ('UNWIND range(1, 10000) AS x MERGE (:Number {value: x}) ' );
375+ self ::markTestSkipped ('Async needs to be implemented before timeout is supported ' );
376+ // if (str_starts_with($alias, 'http')) {
377+ // self::markTestSkipped('HTTP does not support tsx timeout at the moment.');
378+ // }
379+ //
380+ // $this->expectException(ConnectException::class);
381+ // $tsx = $this->getClient()->beginTransaction([], $alias, TransactionConfiguration::default()->withTimeout(1));
382+ // $tsx->run('UNWIND range(1, 10000) AS x MERGE (:Number {value: x})');
361383 }
362384}
0 commit comments