27
27
use WikibaseSolutions \CypherDSL \Literals \Decimal ;
28
28
use WikibaseSolutions \CypherDSL \Literals \StringLiteral ;
29
29
use WikibaseSolutions \CypherDSL \Patterns \Node ;
30
+ use WikibaseSolutions \CypherDSL \PropertyMap ;
30
31
31
32
/**
32
33
* @covers \WikibaseSolutions\CypherDSL\Patterns\Node
33
34
*/
34
35
class NodeTest extends TestCase
35
36
{
36
- public function testEmptyNode ()
37
+ public function testEmptyNode (): void
37
38
{
38
39
$ node = new Node ();
39
40
40
41
$ this ->assertSame ("() " , $ node ->toQuery ());
42
+
43
+ $ this ->assertNull ($ node ->getProperties ());
44
+ $ this ->assertEquals ([], $ node ->getLabels ());
45
+ $ this ->assertNull ($ node ->getVariable ());
46
+
47
+ $ name = $ node ->getName ();
48
+ $ this ->assertNotNull ($ name );
49
+ $ this ->assertSame ($ name , $ node ->getVariable ());
41
50
}
42
51
43
52
/**
44
53
* @dataProvider provideOnlyLabelData
45
54
* @param string $label
46
55
* @param string $expected
47
56
*/
48
- public function testOnlyLabel (string $ label , string $ expected )
57
+ public function testOnlyLabel (string $ label , string $ expected ): void
49
58
{
50
59
$ node = new Node ();
51
60
$ node ->labeled ($ label );
52
61
53
62
$ this ->assertSame ($ expected , $ node ->toQuery ());
63
+
64
+ $ this ->assertNull ($ node ->getProperties ());
65
+ $ this ->assertEquals ([$ label ], $ node ->getLabels ());
66
+ $ this ->assertNull ($ node ->getVariable ());
67
+
68
+ $ name = $ node ->getName ();
69
+ $ this ->assertNotNull ($ name );
70
+ $ this ->assertSame ($ name , $ node ->getVariable ());
54
71
}
55
72
56
73
/**
57
74
* @dataProvider provideOnlyNameData
58
75
* @param string $name
59
76
* @param string $expected
60
77
*/
61
- public function testOnlyName (string $ name , string $ expected )
78
+ public function testOnlyName (string $ name , string $ expected ): void
62
79
{
63
80
$ node = new Node ();
64
81
$ node ->named ($ name );
65
82
66
83
$ this ->assertSame ($ expected , $ node ->toQuery ());
84
+
85
+ $ this ->assertNull ($ node ->getProperties ());
86
+ $ this ->assertEquals ([], $ node ->getLabels ());
87
+ $ this ->assertNotNull ($ node ->getVariable ());
88
+
89
+ $ variable = $ node ->getName ();
90
+ $ this ->assertNotNull ($ variable );
91
+ $ this ->assertEquals ($ name , $ variable ->getVariable ());
92
+ $ this ->assertSame ($ variable , $ node ->getVariable ());
67
93
}
68
94
69
95
/**
70
96
* @dataProvider provideOnlyPropertiesData
71
97
* @param array $properties
72
98
* @param string $expected
73
99
*/
74
- public function testOnlyProperties (array $ properties , string $ expected )
100
+ public function testOnlyProperties (array $ properties , string $ expected ): void
75
101
{
76
102
$ node = new Node ();
77
103
$ node ->withProperties ($ properties );
78
104
79
105
$ this ->assertSame ($ expected , $ node ->toQuery ());
106
+
107
+ $ this ->assertEquals (new PropertyMap ($ properties ), $ node ->getProperties ());
108
+ $ this ->assertEquals ([], $ node ->getLabels ());
109
+ $ this ->assertNull ($ node ->getVariable ());
110
+
111
+ $ name = $ node ->getName ();
112
+ $ this ->assertNotNull ($ name );
113
+ $ this ->assertSame ($ name , $ node ->getVariable ());
80
114
}
81
115
82
116
/**
@@ -85,12 +119,21 @@ public function testOnlyProperties(array $properties, string $expected)
85
119
* @param string $label
86
120
* @param string $expected
87
121
*/
88
- public function testWithNameAndLabel (string $ name , string $ label , string $ expected )
122
+ public function testWithNameAndLabel (string $ name , string $ label , string $ expected ): void
89
123
{
90
124
$ node = new Node ();
91
125
$ node ->labeled ($ label )->named ($ name );
92
126
93
127
$ this ->assertSame ($ expected , $ node ->toQuery ());
128
+
129
+ $ this ->assertNull ($ node ->getProperties ());
130
+ $ this ->assertEquals ([$ label ], $ node ->getLabels ());
131
+ $ this ->assertNotNull ($ node ->getVariable ());
132
+
133
+ $ variable = $ node ->getName ();
134
+ $ this ->assertNotNull ($ variable );
135
+ $ this ->assertEquals ($ name , $ variable ->getVariable ());
136
+ $ this ->assertSame ($ variable , $ node ->getVariable ());
94
137
}
95
138
96
139
/**
@@ -99,12 +142,21 @@ public function testWithNameAndLabel(string $name, string $label, string $expect
99
142
* @param array $properties
100
143
* @param string $expected
101
144
*/
102
- public function testWithNameAndProperties (string $ name , array $ properties , string $ expected )
145
+ public function testWithNameAndProperties (string $ name , array $ properties , string $ expected ): void
103
146
{
104
147
$ node = new Node ();
105
148
$ node ->named ($ name )->withProperties ($ properties );
106
149
107
150
$ this ->assertSame ($ expected , $ node ->toQuery ());
151
+
152
+ $ this ->assertEquals (new PropertyMap ($ properties ), $ node ->getProperties ());
153
+ $ this ->assertEquals ([], $ node ->getLabels ());
154
+ $ this ->assertNotNull ($ node ->getVariable ());
155
+
156
+ $ variable = $ node ->getName ();
157
+ $ this ->assertNotNull ($ variable );
158
+ $ this ->assertEquals ($ name , $ variable ->getVariable ());
159
+ $ this ->assertSame ($ variable , $ node ->getVariable ());
108
160
}
109
161
110
162
/**
@@ -113,12 +165,20 @@ public function testWithNameAndProperties(string $name, array $properties, strin
113
165
* @param array $properties
114
166
* @param string $expected
115
167
*/
116
- public function testWithLabelAndProperties (string $ label , array $ properties , string $ expected )
168
+ public function testWithLabelAndProperties (string $ label , array $ properties , string $ expected ): void
117
169
{
118
170
$ node = new Node ();
119
171
$ node ->labeled ($ label )->withProperties ($ properties );
120
172
121
173
$ this ->assertSame ($ expected , $ node ->toQuery ());
174
+
175
+ $ this ->assertEquals (new PropertyMap ($ properties ), $ node ->getProperties ());
176
+ $ this ->assertEquals ([$ label ], $ node ->getLabels ());
177
+ $ this ->assertNull ($ node ->getVariable ());
178
+
179
+ $ name = $ node ->getName ();
180
+ $ this ->assertNotNull ($ name );
181
+ $ this ->assertSame ($ name , $ node ->getVariable ());
122
182
}
123
183
124
184
/**
@@ -128,19 +188,28 @@ public function testWithLabelAndProperties(string $label, array $properties, str
128
188
* @param array $properties
129
189
* @param string $expected
130
190
*/
131
- public function testWithNameAndLabelAndProperties (string $ name , string $ label , array $ properties , string $ expected )
191
+ public function testWithNameAndLabelAndProperties (string $ name , string $ label , array $ properties , string $ expected ): void
132
192
{
133
193
$ node = new Node ();
134
194
$ node ->named ($ name )->labeled ($ label )->withProperties ($ properties );
135
195
136
196
$ this ->assertSame ($ expected , $ node ->toQuery ());
197
+
198
+ $ this ->assertEquals (new PropertyMap ($ properties ), $ node ->getProperties ());
199
+ $ this ->assertEquals ([$ label ], $ node ->getLabels ());
200
+ $ this ->assertNotNull ($ node ->getVariable ());
201
+
202
+ $ variable = $ node ->getName ();
203
+ $ this ->assertNotNull ($ variable );
204
+ $ this ->assertEquals ($ name , $ variable ->getVariable ());
205
+ $ this ->assertSame ($ variable , $ node ->getVariable ());
137
206
}
138
207
139
208
/**
140
209
* @dataProvider provideBacktickThrowsExceptionData
141
210
* @param Node $invalidNode
142
211
*/
143
- public function testBacktickThrowsException (Node $ invalidNode )
212
+ public function testBacktickThrowsException (Node $ invalidNode ): void
144
213
{
145
214
$ this ->expectException (InvalidArgumentException::class);
146
215
$ invalidNode ->toQuery ();
@@ -151,7 +220,7 @@ public function testBacktickThrowsException(Node $invalidNode)
151
220
* @param array $labels
152
221
* @param string $expected
153
222
*/
154
- public function testMultipleLabels (array $ labels , string $ expected )
223
+ public function testMultipleLabels (array $ labels , string $ expected ): void
155
224
{
156
225
$ node = new Node ();
157
226
@@ -160,9 +229,17 @@ public function testMultipleLabels(array $labels, string $expected)
160
229
}
161
230
162
231
$ this ->assertSame ($ expected , $ node ->toQuery ());
232
+
233
+ $ this ->assertNull ($ node ->getProperties ());
234
+ $ this ->assertEquals ($ labels , $ node ->getLabels ());
235
+ $ this ->assertNull ($ node ->getVariable ());
236
+
237
+ $ name = $ node ->getName ();
238
+ $ this ->assertNotNull ($ name );
239
+ $ this ->assertSame ($ name , $ node ->getVariable ());
163
240
}
164
241
165
- public function testSetterSameAsConstructor ()
242
+ public function testSetterSameAsConstructor (): void
166
243
{
167
244
$ label = "__test__ " ;
168
245
$ viaConstructor = new Node ($ label );
@@ -171,7 +248,7 @@ public function testSetterSameAsConstructor()
171
248
$ this ->assertSame ($ viaConstructor ->toQuery (), $ viaSetter ->toQuery (), "Setting label via setter has different effect than using constructor " );
172
249
}
173
250
174
- public function testAddingProperties ()
251
+ public function testAddingProperties (): void
175
252
{
176
253
$ node = new Node ();
177
254
@@ -192,15 +269,15 @@ public function testAddingProperties()
192
269
$ this ->assertSame ("({foo: 'baz', baz: 'bar', qux: 'baz'}) " , $ node ->toQuery ());
193
270
}
194
271
195
- public function testPropertyWithName ()
272
+ public function testPropertyWithName (): void
196
273
{
197
274
$ node = new Node ();
198
275
$ node ->named ('example ' );
199
276
200
277
$ this ->assertSame ('example.foo ' , $ node ->property ('foo ' )->toQuery ());
201
278
}
202
279
203
- public function testPropertyWithoutName ()
280
+ public function testPropertyWithoutName (): void
204
281
{
205
282
$ node = new Node ();
206
283
0 commit comments