66
77use PHPUnit \Framework \TestCase ;
88use Syndesi \CypherDataStructures \Type \Node ;
9- use Syndesi \CypherDataStructures \Type \NodeLabel ;
10- use Syndesi \CypherDataStructures \Type \PropertyName ;
119use Syndesi \CypherDataStructures \Type \Relation ;
12- use Syndesi \CypherDataStructures \Type \RelationType ;
1310use Syndesi \CypherEntityManager \Exception \InvalidArgumentException ;
1411use Syndesi \CypherEntityManager \Helper \StructureHelper ;
1512
1613class StructureHelperTest extends TestCase
1714{
18- public function testIdentifierStorageToString (): void
15+ public function testEmptyStatement (): void
16+ {
17+ $ statement = StructureHelper::getEmptyStatement ();
18+ $ this ->assertSame ('MATCH (n) LIMIT 0 ' , $ statement ->getText ());
19+ }
20+
21+ public function testIdentifiersToStructure (): void
1922 {
2023 $ node = (new Node ())
21- ->addProperty (new PropertyName ( 'id ' ) , 1000 )
22- ->addProperty (new PropertyName ( '_id ' ) , 1001 )
23- ->addProperty (new PropertyName ( '_z ' ) , 1002 )
24- ->addIdentifier (new PropertyName ( 'id ' ) )
25- ->addIdentifier (new PropertyName ( '_id ' ) )
26- ->addIdentifier (new PropertyName ( '_z ' ) );
24+ ->addProperty ('id ' , 1000 )
25+ ->addProperty ('_id ' , 1001 )
26+ ->addProperty ('_z ' , 1002 )
27+ ->addIdentifier ('id ' )
28+ ->addIdentifier ('_id ' )
29+ ->addIdentifier ('_z ' );
2730 $ this ->assertSame (
2831 '_id, _z, id ' ,
29- StructureHelper::identifierStorageToString ($ node ->getIdentifiers ())
32+ StructureHelper::identifiersToStructure ($ node ->getIdentifiers ())
3033 );
3134 }
3235
3336 public function testGetNodeStructure (): void
3437 {
3538 $ node = (new Node ())
36- ->addNodeLabel ( new NodeLabel ( 'Node ' ) )
37- ->addProperty (new PropertyName ( 'id ' ) , 1234 )
38- ->addProperty (new PropertyName ( 'someKey ' ) , 'some value ' )
39- ->addIdentifier (new PropertyName ( 'id ' ) );
39+ ->addLabel ( 'Node ' )
40+ ->addProperty ('id ' , 1234 )
41+ ->addProperty ('someKey ' , 'some value ' )
42+ ->addIdentifier ('id ' );
4043 $ this ->assertSame ('(:Node id) ' , StructureHelper::getNodeStructure ($ node ));
4144 }
4245
@@ -46,8 +49,8 @@ public function testInvalidGetNodeStructure(): void
4649 $ this ->markTestSkipped ();
4750 }
4851 $ node = (new Node ())
49- ->addNodeLabel ( new NodeLabel ( 'Node ' ) )
50- ->addProperty (new PropertyName ( 'someKey ' ) , 'some value ' );
52+ ->addLabel ( 'Node ' )
53+ ->addProperty ('someKey ' , 'some value ' );
5154 $ this ->expectException (InvalidArgumentException::class);
5255 $ this ->expectExceptionMessage ('at least one identifier is required ' );
5356 StructureHelper::getNodeStructure ($ node );
@@ -56,21 +59,21 @@ public function testInvalidGetNodeStructure(): void
5659 public function testGetRelationStructure (): void
5760 {
5861 $ startNode = (new Node ())
59- ->addNodeLabel ( new NodeLabel ( 'StartNode ' ) )
60- ->addProperty (new PropertyName ( 'id ' ) , 1234 )
61- ->addIdentifier (new PropertyName ( 'id ' ) );
62+ ->addLabel ( 'StartNode ' )
63+ ->addProperty ('id ' , 1234 )
64+ ->addIdentifier ('id ' );
6265
6366 $ endNode = (new Node ())
64- ->addNodeLabel ( new NodeLabel ( 'EndNode ' ) )
65- ->addProperty (new PropertyName ( 'id ' ) , 4321 )
66- ->addIdentifier (new PropertyName ( 'id ' ) );
67+ ->addLabel ( 'EndNode ' )
68+ ->addProperty ('id ' , 4321 )
69+ ->addIdentifier ('id ' );
6770
6871 $ relation = (new Relation ())
69- ->setRelationType ( new RelationType ( 'RELATION ' ) )
72+ ->setType ( 'RELATION ' )
7073 ->setStartNode ($ startNode )
7174 ->setEndNode ($ endNode )
72- ->addProperty (new PropertyName ( 'id ' ) , 1000 )
73- ->addIdentifier (new PropertyName ( 'id ' ) );
75+ ->addProperty ('id ' , 1000 )
76+ ->addIdentifier ('id ' );
7477
7578 $ this ->assertSame ('(:StartNode id)-[RELATION id]->(:EndNode id) ' , StructureHelper::getRelationStructure ($ relation ));
7679 }
@@ -81,18 +84,18 @@ public function testInvalidGetRelationStructureWithMissingStartNode(): void
8184 $ this ->markTestSkipped ();
8285 }
8386 $ endNode = (new Node ())
84- ->addNodeLabel ( new NodeLabel ( 'EndNode ' ) )
85- ->addProperty (new PropertyName ( 'id ' ) , 4321 )
86- ->addIdentifier (new PropertyName ( 'id ' ) );
87+ ->addLabel ( 'EndNode ' )
88+ ->addProperty ('id ' , 4321 )
89+ ->addIdentifier ('id ' );
8790
8891 $ relation = (new Relation ())
89- ->setRelationType ( new RelationType ( 'RELATION ' ) )
92+ ->setType ( 'RELATION ' )
9093 ->setEndNode ($ endNode )
91- ->addProperty (new PropertyName ( 'id ' ) , 1000 )
92- ->addIdentifier (new PropertyName ( 'id ' ) );
94+ ->addProperty ('id ' , 1000 )
95+ ->addIdentifier ('id ' );
9396
9497 $ this ->expectException (InvalidArgumentException::class);
95- $ this ->expectExceptionMessage ('start node can not be null ' );
98+ $ this ->expectExceptionMessage ('Start node of relation can not be null ' );
9699 StructureHelper::getRelationStructure ($ relation );
97100 }
98101
@@ -102,18 +105,18 @@ public function testInvalidGetRelationStructureWithMissingEndNode(): void
102105 $ this ->markTestSkipped ();
103106 }
104107 $ startNode = (new Node ())
105- ->addNodeLabel ( new NodeLabel ( 'StartNode ' ) )
106- ->addProperty (new PropertyName ( 'id ' ) , 1234 )
107- ->addIdentifier (new PropertyName ( 'id ' ) );
108+ ->addLabel ( 'StartNode ' )
109+ ->addProperty ('id ' , 1234 )
110+ ->addIdentifier ('id ' );
108111
109112 $ relation = (new Relation ())
110- ->setRelationType ( new RelationType ( 'RELATION ' ) )
113+ ->setType ( 'RELATION ' )
111114 ->setStartNode ($ startNode )
112- ->addProperty (new PropertyName ( 'id ' ) , 1000 )
113- ->addIdentifier (new PropertyName ( 'id ' ) );
115+ ->addProperty ('id ' , 1000 )
116+ ->addIdentifier ('id ' );
114117
115118 $ this ->expectException (InvalidArgumentException::class);
116- $ this ->expectExceptionMessage ('end node can not be null ' );
119+ $ this ->expectExceptionMessage ('End node of relation can not be null ' );
117120 StructureHelper::getRelationStructure ($ relation );
118121 }
119122
@@ -123,20 +126,20 @@ public function testInvalidGetRelationStructureWithMissingIdentifier(): void
123126 $ this ->markTestSkipped ();
124127 }
125128 $ startNode = (new Node ())
126- ->addNodeLabel ( new NodeLabel ( 'StartNode ' ) )
127- ->addProperty (new PropertyName ( 'id ' ) , 1234 )
128- ->addIdentifier (new PropertyName ( 'id ' ) );
129+ ->addLabel ( 'StartNode ' )
130+ ->addProperty ('id ' , 1234 )
131+ ->addIdentifier ('id ' );
129132
130133 $ endNode = (new Node ())
131- ->addNodeLabel ( new NodeLabel ( 'EndNode ' ) )
132- ->addProperty (new PropertyName ( 'id ' ) , 4321 )
133- ->addIdentifier (new PropertyName ( 'id ' ) );
134+ ->addLabel ( 'EndNode ' )
135+ ->addProperty ('id ' , 4321 )
136+ ->addIdentifier ('id ' );
134137
135138 $ relation = (new Relation ())
136- ->setRelationType ( new RelationType ( 'RELATION ' ) )
139+ ->setType ( 'RELATION ' )
137140 ->setStartNode ($ startNode )
138141 ->setEndNode ($ endNode )
139- ->addProperty (new PropertyName ( 'id ' ) , 1000 );
142+ ->addProperty ('id ' , 1000 );
140143
141144 $ this ->expectException (InvalidArgumentException::class);
142145 $ this ->expectExceptionMessage ('at least one relation identifier is required ' );
0 commit comments