Skip to content

Commit 8becf9f

Browse files
committed
fixed bug with lists in properties
1 parent 41fa5b1 commit 8becf9f

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/Common/TransactionHelper.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Common;
1515

16-
use function is_iterable;
1716
use Laudis\Neo4j\Contracts\TransactionInterface;
1817
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
1918
use Laudis\Neo4j\Exception\Neo4jException;
19+
use Laudis\Neo4j\Types\AbstractCypherSequence;
2020

2121
final class TransactionHelper
2222
{
@@ -59,11 +59,8 @@ public static function retry(callable $tsxFactory, callable $tsxHandler)
5959
*/
6060
private static function triggerLazyResult($tbr): void
6161
{
62-
if (is_iterable($tbr)) {
63-
/** @var mixed $x */
64-
foreach ($tbr as $x) {
65-
self::triggerLazyResult($x);
66-
}
62+
if ($tbr instanceof AbstractCypherSequence) {
63+
$tbr->preload();
6764
}
6865
}
6966
}

src/Formatter/Specialised/JoltHttpOGMTranslator.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace Laudis\Neo4j\Formatter\Specialised;
1515

16+
use function array_key_first;
1617
use Closure;
18+
use function is_array;
1719
use Laudis\Neo4j\Contracts\ConnectionInterface;
1820
use Laudis\Neo4j\Contracts\PointInterface;
1921
use Laudis\Neo4j\Formatter\OGMFormatter;
@@ -206,9 +208,18 @@ private function translateMap(stdClass $value): CypherMap
206208
{
207209
return new CypherMap(
208210
function () use ($value) {
209-
/** @var stdClass|null $element */
211+
/** @var stdClass|array|null $element */
210212
foreach ((array) $value as $key => $element) {
211-
yield $key => $this->translateJoltType($element);
213+
// There is an odd case in the JOLT protocol when dealing with properties in a node. Lists appear not to receive a composite type label, which is why we have to handle them specifically here.
214+
if (is_array($element)) {
215+
if (array_key_first($element) === 0) {
216+
yield $key => new CypherList($element);
217+
} else {
218+
yield $key => new CypherMap($element);
219+
}
220+
} else {
221+
yield $key => $this->translateJoltType($element);
222+
}
212223
}
213224
}
214225
);

src/Http/HttpSession.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ public function beginTransaction(?iterable $statements = null, ?TransactionConfi
179179
$response = $connection->getImplementation()->sendRequest($request);
180180

181181
$response = HttpHelper::interpretResponse($response);
182-
/** @var stdClass|null $info */
183-
$info = $response->info;
184-
if (is_object($info)) {
182+
if (isset($response->info) && $response->info instanceof stdClass) {
185183
/** @var string */
186-
$url = $info->commit;
184+
$url = $response->info->commit;
187185
} else {
188186
/** @var string */
189187
$url = $response->commit;

tests/Integration/ClientIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testEqualEffect(): void
7474
$x = $this->getClient()->runStatement($statement, $prev);
7575
$y = $this->getClient()->runStatement($statement, $current[0]);
7676

77-
self::assertEquals($x->first()->getAsNode('u')->getProperties(), $y->first()->getAsNode('u')->getProperties());
77+
self::assertEquals($x->first()->getAsNode('u')->getProperties()->toArray(), $y->first()->getAsNode('u')->getProperties()->toArray());
7878
}
7979
$prev = $current[0];
8080
}

0 commit comments

Comments
 (0)