Skip to content

Commit a06d3b2

Browse files
committed
introduced serialisation to results
1 parent 69610aa commit a06d3b2

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Types/AbstractCypherSequence.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use function array_key_exists;
1717
use function array_reverse;
1818
use ArrayAccess;
19+
use ArrayIterator;
1920
use BadMethodCallException;
2021
use function call_user_func;
2122
use function count;
2223
use Countable;
24+
use function get_object_vars;
2325
use function implode;
2426
use const INF;
2527
use function is_array;
@@ -533,4 +535,16 @@ protected function isStringable($key): bool
533535
{
534536
return is_string($key) || is_numeric($key) || (is_object($key) && method_exists($key, '__toString'));
535537
}
538+
539+
public function __serialize(): array
540+
{
541+
$this->preload();
542+
543+
$tbr = get_object_vars($this);
544+
$tbr['generator'] = new ArrayIterator($this->cache);
545+
$tbr['currentPosition'] = 0;
546+
$tbr['generatorPosition'] = 0;
547+
548+
return $tbr;
549+
}
536550
}

tests/Integration/SummarizedResultFormatterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use Laudis\Neo4j\Types\CypherList;
2424
use Laudis\Neo4j\Types\CypherMap;
2525
use function random_bytes;
26+
use function serialize;
27+
use function unserialize;
2628

2729
/**
2830
* @psalm-import-type OGMTypes from \Laudis\Neo4j\Formatter\OGMFormatter
@@ -82,4 +84,17 @@ public function testGetResults(string $alias): void
8284
self::assertInstanceOf(CypherMap::class, $first);
8385
self::assertEquals(1, $first->get('one'));
8486
}
87+
88+
/**
89+
* @dataProvider connectionAliases
90+
*/
91+
public function testSerialize(string $alias): void
92+
{
93+
$results = $this->getClient()->run('RETURN 1 AS one', [], $alias);
94+
95+
$serialise = serialize($results);
96+
$resultHasBeenSerialized = unserialize($serialise);
97+
98+
self::assertEquals($results->toRecursiveArray(), $resultHasBeenSerialized->toRecursiveArray());
99+
}
85100
}

0 commit comments

Comments
 (0)