Skip to content

Commit 2de50a1

Browse files
committed
added the test code for float and 3D point datatype
1 parent 450102a commit 2de50a1

File tree

10 files changed

+274
-58
lines changed

10 files changed

+274
-58
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/OGM.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public function map(array $object): mixed
1212
{
1313
return match ($object['$type']) {
1414
'Integer' => $object['_value'],
15+
'float' => $object['_value'],
1516
'String' => $object['_value'],
1617
'Boolean' => $object['_value'],
1718
'Null' => $object['_value'],
@@ -79,4 +80,5 @@ private function mapProperties(array $properties): array
7980
}
8081
return $mappedProperties;
8182
}
83+
8284
}

src/Objects/Node.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
11
<?php
2+
23
namespace Neo4j\QueryAPI\Objects;
34

5+
/**
6+
* Represents a Neo4j Node with labels and properties.
7+
*/
48
class Node
59
{
6-
private $labels;
7-
private $properties;
10+
/**
11+
* @var string[] Array of labels for the node.
12+
*/
13+
private array $labels;
14+
15+
/**
16+
* @var array<string, mixed> Associative array of properties (key-value pairs).
17+
*/
18+
private array $properties;
819

20+
/**
21+
* Node constructor.
22+
*
23+
* @param string[] $labels Array of labels for the node.
24+
* @param array<string, mixed> $properties Associative array of properties.
25+
*/
926
public function __construct(array $labels, array $properties)
1027
{
1128
$this->labels = $labels;
1229
$this->properties = $properties;
1330
}
1431

32+
/**
33+
* Get the labels of the node.
34+
*
35+
* @return string[] Array of labels.
36+
*/
1537
public function getLabels(): array
1638
{
1739
return $this->labels;
1840
}
1941

42+
/**
43+
* Get the properties of the node.
44+
*
45+
* @return array<string, mixed> Associative array of properties.
46+
*/
2047
public function getProperties(): array
2148
{
2249
return $this->properties;
2350
}
2451
}
25-

src/Objects/Path.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
11
<?php
22

3-
43
namespace Neo4j\QueryAPI\Objects;
54

5+
/**
6+
* Represents a path in a Neo4j graph, consisting of nodes and relationships.
7+
*/
68
class Path
79
{
8-
private $nodes;
9-
private $relationships;
10+
/**
11+
* @var Node[] Array of nodes in the path.
12+
*/
13+
private array $nodes;
14+
15+
/**
16+
* @var Relationship[] Array of relationships in the path.
17+
*/
18+
private array $relationships;
1019

20+
/**
21+
* Path constructor.
22+
*
23+
* @param Node[] $nodes Array of nodes in the path.
24+
* @param Relationship[] $relationships Array of relationships in the path.
25+
*/
1126
public function __construct(array $nodes, array $relationships)
1227
{
1328
$this->nodes = $nodes;
1429
$this->relationships = $relationships;
1530
}
1631

17-
public function getNodes()
32+
/**
33+
* Get the nodes in the path.
34+
*
35+
* @return Node[] Array of nodes.
36+
*/
37+
public function getNodes(): array
1838
{
1939
return $this->nodes;
2040
}
2141

22-
public function getRelationships()
42+
/**
43+
* Get the relationships in the path.
44+
*
45+
* @return Relationship[] Array of relationships.
46+
*/
47+
public function getRelationships(): array
2348
{
2449
return $this->relationships;
2550
}
26-
}
51+
}

src/Objects/Person.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<?php
2+
23
namespace Neo4j\QueryAPI\Objects;
34

5+
/**
6+
* Represents a Person node in the Neo4j graph.
7+
*/
48
class Person extends Node
59
{
10+
/**
11+
* Person constructor.
12+
*
13+
* @param array<string, mixed> $properties Associative array of properties for the Person node.
14+
*/
615
public function __construct(array $properties)
716
{
8-
parent::__construct(['Person'], $properties); // Pass the labels and properties correctly
17+
// Pass the label 'Person' along with the properties to the parent Node constructor.
18+
parent::__construct(['Person'], $properties);
919
}
1020
}

src/Objects/Point.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,58 @@
22

33
namespace Neo4j\QueryAPI\Objects;
44

5+
/**
6+
* Represents a geographical point with longitude, latitude, and SRID (Spatial Reference System Identifier).
7+
*/
58
class Point
69
{
10+
/**
11+
* @param float $longitude The longitude of the point.
12+
* @param float $latitude The latitude of the point.
13+
* @param int $srid The Spatial Reference System Identifier (SRID).
14+
*/
715
public function __construct(
816
public float $longitude,
917
public float $latitude,
1018
public int $srid
11-
)
12-
{
19+
) {
1320
}
1421

15-
22+
/**
23+
* Get the longitude of the point.
24+
*
25+
* @return float Longitude value.
26+
*/
1627
public function getLongitude(): float
1728
{
1829
return $this->longitude;
1930
}
2031

21-
32+
/**
33+
* Get the latitude of the point.
34+
*
35+
* @return float Latitude value.
36+
*/
2237
public function getLatitude(): float
2338
{
2439
return $this->latitude;
2540
}
2641

27-
42+
/**
43+
* Get the SRID (Spatial Reference System Identifier) of the point.
44+
*
45+
* @return int SRID value.
46+
*/
2847
public function getSrid(): int
2948
{
3049
return $this->srid;
3150
}
3251

33-
52+
/**
53+
* Convert the Point object to a string representation.
54+
*
55+
* @return string String representation in the format: "SRID=<srid>;POINT (<longitude> <latitude>)".
56+
*/
3457
public function __toString(): string
3558
{
3659
return "SRID={$this->srid};POINT ({$this->longitude} {$this->latitude})";

src/Objects/Point_3D.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Neo4j\QueryAPI\Objects;
4+
5+
/**
6+
* Represents a geographical 3D point with longitude, latitude, altitude, and SRID (Spatial Reference System Identifier).
7+
*/
8+
class Point_3D
9+
{
10+
/**
11+
* @param float $longitude The longitude of the point.
12+
* @param float $latitude The latitude of the point.
13+
* @param float $altitude The altitude of the point.
14+
* @param int $srid The Spatial Reference System Identifier (SRID).
15+
*/
16+
public function __construct(
17+
public float $longitude,
18+
public float $latitude,
19+
public float $altitude,
20+
public int $srid
21+
) {
22+
}
23+
24+
/**
25+
* Get the longitude of the point.
26+
*
27+
* @return float Longitude value.
28+
*/
29+
public function getLongitude(): float
30+
{
31+
return $this->longitude;
32+
}
33+
34+
/**
35+
* Get the latitude of the point.
36+
*
37+
* @return float Latitude value.
38+
*/
39+
public function getLatitude(): float
40+
{
41+
return $this->latitude;
42+
}
43+
44+
/**
45+
* Get the altitude of the point.
46+
*
47+
* @return float Altitude value.
48+
*/
49+
public function getAltitude(): float
50+
{
51+
return $this->altitude;
52+
}
53+
54+
/**
55+
* Get the SRID (Spatial Reference System Identifier) of the point.
56+
*
57+
* @return int SRID value.
58+
*/
59+
public function getSrid(): int
60+
{
61+
return $this->srid;
62+
}
63+
64+
/**
65+
* Convert the Point3D object to a string representation.
66+
*
67+
* @return string String representation in the format: "SRID=<srid>;POINT ( <longitude> <latitude> <altitude> )".
68+
*/
69+
public function __toString(): string
70+
{
71+
return "SRID={$this->srid};POINT ({$this->longitude} {$this->latitude} {$this->altitude})";
72+
}
73+
}

src/Objects/Relationship.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
<?php
22

3-
43
namespace Neo4j\QueryAPI\Objects;
54

5+
/**
6+
* Represents a relationship in a Neo4j graph, with a type and associated properties.
7+
*/
68
class Relationship
79
{
8-
private $type;
9-
private $properties;
10+
/**
11+
* @var string The type of the relationship (e.g., "FRIENDS_WITH", "WORKS_FOR").
12+
*/
13+
private string $type;
14+
15+
/**
16+
* @var array<string, mixed> Associative array of properties for the relationship.
17+
*/
18+
private array $properties;
1019

11-
public function __construct($type, array $properties = [])
20+
/**
21+
* Relationship constructor.
22+
*
23+
* @param string $type The type of the relationship.
24+
* @param array<string, mixed> $properties Associative array of properties for the relationship.
25+
*/
26+
public function __construct(string $type, array $properties = [])
1227
{
1328
$this->type = $type;
1429
$this->properties = $properties;
1530
}
1631

17-
public function getType()
32+
/**
33+
* Get the type of the relationship.
34+
*
35+
* @return string The type of the relationship.
36+
*/
37+
public function getType(): string
1838
{
1939
return $this->type;
2040
}
2141

22-
public function getProperties()
42+
/**
43+
* Get the properties of the relationship.
44+
*
45+
* @return array<string, mixed> Associative array of properties.
46+
*/
47+
public function getProperties(): array
2348
{
2449
return $this->properties;
2550
}

tests/Integration/Neo4jOGMTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Neo4j\QueryAPI\Objects\Path;
66
use Neo4j\QueryAPI\Objects\Person;
77
use Neo4j\QueryAPI\Objects\Point;
8+
use Neo4j\QueryAPI\Objects\Point_3D;
89
use Neo4j\QueryAPI\Objects\Relationship;
910
use Neo4j\QueryAPI\OGM;
1011
use PHPUnit\Framework\TestCase;
@@ -26,6 +27,14 @@ public function testInteger(): void
2627
]));
2728
}
2829

30+
public function testFloat(): void
31+
{
32+
$this->assertEquals(1.75, $this->ogm->map([
33+
'$type' => 'float',
34+
'_value' => 1.75,
35+
]));
36+
}
37+
2938
public function testString(): void
3039
{
3140
$this->assertEquals('Alice', $this->ogm->map([
@@ -223,4 +232,8 @@ public function testWithPath()
223232
$this->assertEquals('A', $path->getNodes()[0]->getProperties()['name']['_value']);
224233
$this->assertEquals('B', $path->getNodes()[1]->getProperties()['name']['_value']);
225234
}
235+
236+
237+
238+
226239
}

0 commit comments

Comments
 (0)