22
33namespace Neo4j \QueryAPI \Tests \Integration ;
44
5+ use Neo4j \QueryAPI \Objects \Person ;
6+ use Neo4j \QueryAPI \Objects \Point ;
7+ use Neo4j \QueryAPI \Objects \Relationship ;
58use Neo4j \QueryAPI \OGM ;
69use PHPUnit \Framework \TestCase ;
710
@@ -22,11 +25,149 @@ public function testInteger(): void
2225 ]));
2326 }
2427
28+ public function testString (): void
29+ {
30+ $ this ->assertEquals ('Alice ' , $ this ->ogm ->map ([
31+ '$type ' => 'String ' ,
32+ '_value ' => 'Alice ' ,
33+ ]));
34+ }
35+
36+ public function testBoolean (): void
37+ {
38+ $ this ->assertEquals (true , $ this ->ogm ->map ([
39+ '$type ' => 'Boolean ' ,
40+ '_value ' => true ,
41+ ]));
42+ }
43+
44+ public function testNull (): void
45+ {
46+ $ this ->assertEquals (null , $ this ->ogm ->map ([
47+ '$type ' => 'Null ' ,
48+ '_value ' => null ,
49+ ]));
50+ }
51+
52+ public function testDate (): void
53+ {
54+ $ this ->assertEquals ('2024-12-11T11:00:00Z ' , $ this ->ogm ->map ([
55+ '$type ' => 'OffsetDateTime ' ,
56+ '_value ' => '2024-12-11T11:00:00Z ' ,
57+ ]));
58+ }
59+ public function testDuration (): void
60+ {
61+ $ this ->assertEquals ('P14DT16H12M ' , $ this ->ogm ->map ([
62+ '$type ' => 'Duration ' ,
63+ '_value ' => 'P14DT16H12M ' ,
64+ ]));
65+ }
66+
67+
2568 public function testPoint (): void
2669 {
27- $ this -> assertEquals ( 30 , $ this ->ogm ->map ([
70+ $ point = $ this ->ogm ->map ([
2871 '$type ' => 'Point ' ,
2972 '_value ' => 'SRID=4326;POINT (1.2 3.4) ' ,
73+ ]);
74+
75+ $ this ->assertInstanceOf (Point::class, $ point );
76+ $ this ->assertEquals (1.2 , $ point ->getLongitude ());
77+ $ this ->assertEquals (3.4 , $ point ->getLatitude ());
78+ $ this ->assertEquals (4326 , $ point ->getSrid ());
79+ }
80+ public function testArray (): void
81+ {
82+ $ arrayData = ['developer ' , 'python ' , 'neo4j ' ];
83+
84+ $ this ->assertEquals ($ arrayData , $ this ->ogm ->map ([
85+ '$type ' => 'Array ' ,
86+ '_value ' => $ arrayData ,
3087 ]));
3188 }
89+ public function testWithNode ()
90+ {
91+ // Simulate the result from the Neo4j database query
92+ $ data = [
93+ 'data ' => [
94+ 'fields ' => ['n ' ],
95+ 'values ' => [
96+ [
97+ [
98+ '$type ' => 'Node ' ,
99+ '_value ' => [
100+ '_labels ' => ['Person ' ],
101+ '_properties ' => [
102+ 'name ' => ['_value ' => 'Ayush ' ],
103+ 'age ' => ['_value ' => 30 ],
104+ 'location ' => ['_value ' => 'New York ' ],
105+ ]
106+ ],
107+ ]
108+ ]
109+ ]
110+ ]
111+ ];
112+
113+
114+ $ nodeData = $ data ['data ' ]['values ' ][0 ][0 ]['_value ' ];
115+ $ node = new Person ($ nodeData ['_properties ' ]);
116+
117+ $ properties = $ node ->getProperties ();
118+
119+ $ this ->assertEquals ('Ayush ' , $ properties ['name ' ]['_value ' ]); // Ensure 'name' is a string
120+ $ this ->assertEquals (30 , $ properties ['age ' ]['_value ' ]); // Ensure 'age' is an integer
121+ $ this ->assertEquals ('New York ' , $ properties ['location ' ]['_value ' ]); // Ensure 'location' is a string
122+ }
123+
124+ public function testWithSimpleRelationship ()
125+ {
126+ // Simulate the result from the Neo4j database query
127+ $ data = [
128+ 'data ' => [
129+ 'fields ' => ['a ' , 'b ' , 'r ' ],
130+ 'values ' => [
131+ [
132+ [
133+ '$type ' => 'Node ' ,
134+ '_value ' => [
135+ '_labels ' => ['Person ' ],
136+ '_properties ' => ['name ' => ['_value ' => 'A ' ]]
137+ ]
138+ ],
139+ [
140+ '$type ' => 'Node ' ,
141+ '_value ' => [
142+ '_labels ' => ['Person ' ],
143+ '_properties ' => ['name ' => ['_value ' => 'B ' ]]
144+ ]
145+ ],
146+ [
147+ '$type ' => 'Relationship ' ,
148+ '_value ' => [
149+ '_type ' => 'FRIENDS ' ,
150+ '_properties ' => []
151+ ]
152+ ]
153+ ]
154+ ]
155+ ]
156+ ];
157+
158+ // Parse the response and create the nodes and relationship
159+ $ aData = $ data ['data ' ]['values ' ][0 ][0 ]['_value ' ];
160+ $ bData = $ data ['data ' ]['values ' ][0 ][1 ]['_value ' ];
161+ $ relationshipData = $ data ['data ' ]['values ' ][0 ][2 ]['_value ' ];
162+
163+ $ aNode = new Person ($ aData ['_properties ' ]);
164+ $ bNode = new Person ($ bData ['_properties ' ]);
165+ $ relationship = new Relationship ($ relationshipData ['_type ' ], $ relationshipData ['_properties ' ]);
166+
167+ // Assertions
168+ $ this ->assertEquals ('A ' , $ aNode ->getProperties ()['name ' ]['_value ' ]);
169+ $ this ->assertEquals ('B ' , $ bNode ->getProperties ()['name ' ]['_value ' ]);
170+ $ this ->assertEquals ('FRIENDS ' , $ relationship ->getType ());
171+ }
172+
32173}
0 commit comments