Skip to content

Commit 8d5815d

Browse files
committed
expanded Pattern Tests
1 parent 88a4aef commit 8d5815d

File tree

4 files changed

+316
-50
lines changed

4 files changed

+316
-50
lines changed

src/Patterns/Node.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ class Node implements NodeType
4949
/**
5050
* @var Variable|null
5151
*/
52-
private ?Variable $variable;
52+
private ?Variable $variable = null;
5353

5454
/**
5555
* @var MapType|null
5656
*/
57-
private ?MapType $properties;
57+
private ?MapType $properties = null;
5858

5959
/**
6060
* Returns the labels of the node.

src/Patterns/Path.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,27 @@ class Path implements PathType
7171
/**
7272
* @var Variable|null
7373
*/
74-
private ?Variable $variable;
74+
private ?Variable $variable = null;
7575

7676
/**
7777
* @var int|null The minimum number of `relationship->node` hops away to search
7878
*/
79-
private ?int $minHops;
79+
private ?int $minHops = null;
8080

8181
/**
8282
* @var int|null The maximum number of `relationship->node` hops away to search
8383
*/
84-
private ?int $maxHops;
84+
private ?int $maxHops = null;
8585

8686
/**
8787
* @var int|null The exact number of `relationship->node` hops away to search
8888
*/
89-
private ?int $exactHops;
89+
private ?int $exactHops = null;
9090

9191
/**
9292
* @var MapType|null
9393
*/
94-
private ?MapType $properties;
94+
private ?MapType $properties = null;
9595

9696
/**
9797
* Path constructor.
@@ -334,7 +334,7 @@ public function getProperties(): ?MapType
334334
/**
335335
* Returns the variable of the path.
336336
*
337-
* @return Variable
337+
* @return Variable|null
338338
*/
339339
public function getVariable(): ?Variable
340340
{

tests/Unit/Patterns/NodeTest.php

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,90 @@
2727
use WikibaseSolutions\CypherDSL\Literals\Decimal;
2828
use WikibaseSolutions\CypherDSL\Literals\StringLiteral;
2929
use WikibaseSolutions\CypherDSL\Patterns\Node;
30+
use WikibaseSolutions\CypherDSL\PropertyMap;
3031

3132
/**
3233
* @covers \WikibaseSolutions\CypherDSL\Patterns\Node
3334
*/
3435
class NodeTest extends TestCase
3536
{
36-
public function testEmptyNode()
37+
public function testEmptyNode(): void
3738
{
3839
$node = new Node();
3940

4041
$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());
4150
}
4251

4352
/**
4453
* @dataProvider provideOnlyLabelData
4554
* @param string $label
4655
* @param string $expected
4756
*/
48-
public function testOnlyLabel(string $label, string $expected)
57+
public function testOnlyLabel(string $label, string $expected): void
4958
{
5059
$node = new Node();
5160
$node->labeled($label);
5261

5362
$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());
5471
}
5572

5673
/**
5774
* @dataProvider provideOnlyNameData
5875
* @param string $name
5976
* @param string $expected
6077
*/
61-
public function testOnlyName(string $name, string $expected)
78+
public function testOnlyName(string $name, string $expected): void
6279
{
6380
$node = new Node();
6481
$node->named($name);
6582

6683
$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());
6793
}
6894

6995
/**
7096
* @dataProvider provideOnlyPropertiesData
7197
* @param array $properties
7298
* @param string $expected
7399
*/
74-
public function testOnlyProperties(array $properties, string $expected)
100+
public function testOnlyProperties(array $properties, string $expected): void
75101
{
76102
$node = new Node();
77103
$node->withProperties($properties);
78104

79105
$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());
80114
}
81115

82116
/**
@@ -85,12 +119,21 @@ public function testOnlyProperties(array $properties, string $expected)
85119
* @param string $label
86120
* @param string $expected
87121
*/
88-
public function testWithNameAndLabel(string $name, string $label, string $expected)
122+
public function testWithNameAndLabel(string $name, string $label, string $expected): void
89123
{
90124
$node = new Node();
91125
$node->labeled($label)->named($name);
92126

93127
$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());
94137
}
95138

96139
/**
@@ -99,12 +142,21 @@ public function testWithNameAndLabel(string $name, string $label, string $expect
99142
* @param array $properties
100143
* @param string $expected
101144
*/
102-
public function testWithNameAndProperties(string $name, array $properties, string $expected)
145+
public function testWithNameAndProperties(string $name, array $properties, string $expected): void
103146
{
104147
$node = new Node();
105148
$node->named($name)->withProperties($properties);
106149

107150
$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());
108160
}
109161

110162
/**
@@ -113,12 +165,20 @@ public function testWithNameAndProperties(string $name, array $properties, strin
113165
* @param array $properties
114166
* @param string $expected
115167
*/
116-
public function testWithLabelAndProperties(string $label, array $properties, string $expected)
168+
public function testWithLabelAndProperties(string $label, array $properties, string $expected): void
117169
{
118170
$node = new Node();
119171
$node->labeled($label)->withProperties($properties);
120172

121173
$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());
122182
}
123183

124184
/**
@@ -128,19 +188,28 @@ public function testWithLabelAndProperties(string $label, array $properties, str
128188
* @param array $properties
129189
* @param string $expected
130190
*/
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
132192
{
133193
$node = new Node();
134194
$node->named($name)->labeled($label)->withProperties($properties);
135195

136196
$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());
137206
}
138207

139208
/**
140209
* @dataProvider provideBacktickThrowsExceptionData
141210
* @param Node $invalidNode
142211
*/
143-
public function testBacktickThrowsException(Node $invalidNode)
212+
public function testBacktickThrowsException(Node $invalidNode): void
144213
{
145214
$this->expectException(InvalidArgumentException::class);
146215
$invalidNode->toQuery();
@@ -151,7 +220,7 @@ public function testBacktickThrowsException(Node $invalidNode)
151220
* @param array $labels
152221
* @param string $expected
153222
*/
154-
public function testMultipleLabels(array $labels, string $expected)
223+
public function testMultipleLabels(array $labels, string $expected): void
155224
{
156225
$node = new Node();
157226

@@ -160,9 +229,17 @@ public function testMultipleLabels(array $labels, string $expected)
160229
}
161230

162231
$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());
163240
}
164241

165-
public function testSetterSameAsConstructor()
242+
public function testSetterSameAsConstructor(): void
166243
{
167244
$label = "__test__";
168245
$viaConstructor = new Node($label);
@@ -171,7 +248,7 @@ public function testSetterSameAsConstructor()
171248
$this->assertSame($viaConstructor->toQuery(), $viaSetter->toQuery(), "Setting label via setter has different effect than using constructor");
172249
}
173250

174-
public function testAddingProperties()
251+
public function testAddingProperties(): void
175252
{
176253
$node = new Node();
177254

@@ -192,15 +269,15 @@ public function testAddingProperties()
192269
$this->assertSame("({foo: 'baz', baz: 'bar', qux: 'baz'})", $node->toQuery());
193270
}
194271

195-
public function testPropertyWithName()
272+
public function testPropertyWithName(): void
196273
{
197274
$node = new Node();
198275
$node->named('example');
199276

200277
$this->assertSame('example.foo', $node->property('foo')->toQuery());
201278
}
202279

203-
public function testPropertyWithoutName()
280+
public function testPropertyWithoutName(): void
204281
{
205282
$node = new Node();
206283

0 commit comments

Comments
 (0)