Skip to content

Commit 6db361a

Browse files
PratikshaPratiksha
authored andcommitted
seperated all integration tests
1 parent e00b7d8 commit 6db361a

File tree

10 files changed

+216
-1017
lines changed

10 files changed

+216
-1017
lines changed

src/Objects/Node.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,14 @@
88

99
class Node
1010
{
11-
/**
12-
* @var string[] Array of labels for the node.
13-
*/
14-
private array $labels;
15-
16-
/**
17-
* @var array<string, mixed> Associative array of properties (key-value pairs).
18-
*/
19-
private array $properties;
20-
2111
/**
2212
* Node constructor
2313
*
2414
* @param string[] $labels Array of labels for the node.
2515
* @param array<string, mixed> $properties Associative array of properties.
2616
*/
27-
public function __construct(array $labels, array $properties)
28-
{
29-
$this->labels = $labels;
30-
$this->properties = $properties;
31-
}
32-
33-
/**
34-
* Get the properties of the node.
35-
* @return array<string, mixed> Associative array of properties.
36-
*/
37-
public function getProperties(): array
17+
public function __construct(public readonly array $labels, public readonly array $properties)
3818
{
39-
return $this->properties;
4019
}
4120

4221
/**
@@ -50,4 +29,13 @@ public function toArray(): array
5029
'_properties' => $this->properties,
5130
];
5231
}
32+
public function getProperties(): array
33+
{
34+
return $this->properties;
35+
}
36+
37+
public function getLabels(): array
38+
{
39+
return $this->labels;
40+
}
5341
}

src/Objects/Path.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@ public function __construct(array $nodes, array $relationships)
3030
$this->relationships = $relationships;
3131
}
3232

33+
public function getNodes(): array
34+
{
35+
return $this->nodes;
36+
}
37+
38+
public function getRelationships(): array
39+
{
40+
return $this->relationships;
41+
}
42+
3343
}

src/Objects/Point.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,21 @@ public function __toString(): string
3030
{
3131
return "SRID={$this->srid};POINT ({$this->x} {$this->y})";
3232
}
33+
34+
public function getX(): float
35+
{
36+
return $this->x;
37+
}
38+
public function getY(): float
39+
{
40+
return $this->y;
41+
}
42+
public function getZ(): float
43+
{
44+
return $this->z;
45+
}
46+
public function getSrid(): float
47+
{
48+
return $this->srid;
49+
}
3350
}

src/Objects/Relationship.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,15 @@ public function __construct(string $type, array $properties = [])
3030
$this->properties = $properties;
3131
}
3232

33+
public function getType(): string
34+
{
35+
return $this->type;
36+
}
37+
38+
public function getProperties(): array
39+
{
40+
return $this->properties;
41+
}
42+
43+
3344
}

src/ResponseParser.php

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Neo4j\QueryAPI\Results\ResultRow;
1313
use RuntimeException;
1414
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
15-
use Neo4j\QueryAPI\Objects\Point;
1615

1716
class ResponseParser
1817
{
@@ -50,45 +49,21 @@ private function validateAndDecodeResponse(ResponseInterface $response): array
5049
return $data;
5150
}
5251

53-
/**
54-
* @return list<ResultRow>
55-
*/
56-
/**
57-
* @param list<string> $fields
58-
* @param list<array<array-key, mixed>> $values
59-
* @return list<ResultRow>
60-
*/
61-
private function mapRows(array $fields, array $values): array
52+
private function mapRows(array $keys, array $values): array
6253
{
63-
return array_map(
64-
fn (array $row): ResultRow => new ResultRow(
65-
array_combine(
66-
$fields,
67-
array_map([$this, 'formatOGMOutput'], $row)
68-
) ?: [] // Ensure array_combine never returns false
69-
),
70-
$values
71-
);
72-
}
73-
74-
/**
75-
* Ensures mapped output follows expected format
76-
*
77-
* @param mixed $value
78-
* @return mixed
79-
*/
80-
private function formatOGMOutput(mixed $value): mixed
81-
{
82-
if (is_array($value) && array_key_exists('$type', $value) && array_key_exists('_value', $value)) {
83-
return $this->ogm->map($value);
84-
}
85-
86-
return $value;
54+
return array_map(function ($row) use ($keys) {
55+
$mapped = [];
56+
foreach ($keys as $index => $key) {
57+
$fieldData = $row[$index] ?? null;
58+
if (is_string($fieldData)) {
59+
$fieldData = ['$type' => 'String', '_value' => $fieldData];
60+
}
61+
$mapped[$key] = $this->ogm->map($fieldData);
62+
}
63+
return new ResultRow($mapped);
64+
}, $values);
8765
}
8866

89-
90-
91-
9267
private function buildCounters(array $countersData): ResultCounters
9368
{
9469
return new ResultCounters(
@@ -120,22 +95,17 @@ private function getAccessMode(string $accessModeData): AccessMode
12095

12196
private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPlan
12297
{
123-
if ($queryPlanData === null || empty($queryPlanData)) {
98+
if (!$queryPlanData) {
12499
return null;
125100
}
126101

127-
/**
128-
* @var array<string, mixed> $mappedArguments
129-
*/
130-
$mappedArguments = array_map(function (mixed $value): mixed {
131-
if (is_array($value) && isset($value['$type']) && isset($value['_value'])) {
102+
$mappedArguments = array_map(function ($value) {
103+
if (is_array($value) && array_key_exists('$type', $value) && array_key_exists('_value', $value)) {
132104
return $this->ogm->map($value);
133105
}
134-
135106
return $value;
136107
}, $queryPlanData['arguments'] ?? []);
137108

138-
139109
$queryArguments = new ProfiledQueryPlanArguments(
140110
globalMemory: $mappedArguments['GlobalMemory'] ?? null,
141111
plannerImpl: $mappedArguments['planner-impl'] ?? null,
@@ -158,11 +128,7 @@ private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPl
158128
planner: $mappedArguments['planner'] ?? null,
159129
rows: $mappedArguments['Rows'] ?? null
160130
);
161-
162-
$children = array_map(
163-
fn (array $child): ?ProfiledQueryPlan => $this->buildProfiledQueryPlan($child),
164-
$queryPlanData['children'] ?? []
165-
);
131+
$children = array_map(fn ($child) => $this->buildProfiledQueryPlan($child), $queryPlanData['children'] ?? []);
166132

167133
return new ProfiledQueryPlan(
168134
$queryPlanData['dbHits'] ?? 0,
@@ -178,5 +144,4 @@ private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPl
178144
$queryPlanData['identifiers'] ?? []
179145
);
180146
}
181-
182147
}

src/Results/ResultSet.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public function getIterator(): Traversable
3838
return new ArrayIterator($this->rows);
3939
}
4040

41-
public function getProfiledQueryPlan(): ?ProfiledQueryPlan
42-
{
43-
return $this->profiledQueryPlan;
44-
}
4541
public function getQueryCounters(): ?ResultCounters
4642
{
4743
return $this->counters;
@@ -54,4 +50,23 @@ public function count(): int
5450
return count($this->rows);
5551
}
5652

53+
public function getBookmarks(): ?Bookmarks
54+
{
55+
return $this->bookmarks;
56+
}
57+
58+
public function getAccessMode(): ?AccessMode
59+
{
60+
return $this->accessMode;
61+
}
62+
63+
public function getData(): array
64+
{
65+
return $this->rows;
66+
}
67+
68+
public function getProfiledQueryPlan(): ?ProfiledQueryPlan
69+
{
70+
return $this->profiledQueryPlan;
71+
}
5772
}

0 commit comments

Comments
 (0)