Skip to content

Commit e1f9bf1

Browse files
author
Wout Gevaert
committed
Write unit tests & add missing use
1 parent 88bb8ee commit e1f9bf1

File tree

6 files changed

+113
-5
lines changed

6 files changed

+113
-5
lines changed

src/Clauses/CreateClause.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24+
use WikibaseSolutions\CypherDSL\Assignment;
2425
use WikibaseSolutions\CypherDSL\ErrorHandling\ErrorHelper;
2526
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2627

tests/Unit/Clauses/CreateClauseTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use TypeError;
2626
use WikibaseSolutions\CypherDSL\Clauses\CreateClause;
2727
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
28+
use WikibaseSolutions\CypherDSL\Assignment;
2829
use WikibaseSolutions\CypherDSL\Types\AnyType;
2930
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
3031
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
@@ -93,6 +94,19 @@ public function testAcceptsPathType()
9394
$createClause->toQuery();
9495
}
9596

97+
/**
98+
* @doesNotPerformAssertions
99+
*/
100+
public function testAcceptsAssignment()
101+
{
102+
$createClause = new CreateClause();
103+
104+
$patternA = $this->getQueryConvertableMock(Assignment::class, "p = (a)-->(b)");
105+
106+
$createClause->addPattern($patternA);
107+
$createClause->toQuery();
108+
}
109+
96110
public function testDoesNotAcceptAnyType()
97111
{
98112
$createClause = new CreateClause();
@@ -104,4 +118,4 @@ public function testDoesNotAcceptAnyType()
104118
$createClause->addPattern($patternA);
105119
$createClause->toQuery();
106120
}
107-
}
121+
}

tests/Unit/Clauses/MatchClauseTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use PHPUnit\Framework\TestCase;
2525
use TypeError;
26+
use WikibaseSolutions\CypherDSL\Assignment;
2627
use WikibaseSolutions\CypherDSL\Clauses\MatchClause;
2728
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
2829
use WikibaseSolutions\CypherDSL\Types\AnyType;
@@ -83,6 +84,18 @@ public function testAcceptsPathType()
8384
$match->toQuery();
8485
}
8586

87+
/**
88+
* @doesNotPerformAssertions
89+
*/
90+
public function testAcceptsAssignment()
91+
{
92+
$match = new MatchClause();
93+
94+
$match->addPattern($this->getQueryConvertableMock(Assignment::class, "p = (a)-->(b)"));
95+
96+
$match->toQuery();
97+
}
98+
8699
public function testDoesNotAcceptAnyType()
87100
{
88101
$this->expectException(TypeError::class);
@@ -92,4 +105,4 @@ public function testDoesNotAcceptAnyType()
92105

93106
$match->toQuery();
94107
}
95-
}
108+
}

tests/Unit/Clauses/MergeClauseTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use PHPUnit\Framework\TestCase;
2525
use TypeError;
26+
use WikibaseSolutions\CypherDSL\Assignment;
2627
use WikibaseSolutions\CypherDSL\Clauses\Clause;
2728
use WikibaseSolutions\CypherDSL\Clauses\MergeClause;
2829
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
@@ -121,6 +122,19 @@ public function testAcceptsPathType()
121122
$merge->toQuery();
122123
}
123124

125+
/**
126+
* @doesNotPerformAssertions
127+
*/
128+
public function testAcceptsAssignment()
129+
{
130+
$merge = new MergeClause();
131+
$pattern = $this->getQueryConvertableMock(Assignment::class, "p = (a)-->(b)");
132+
133+
$merge->setPattern($pattern);
134+
135+
$merge->toQuery();
136+
}
137+
124138
public function testDoesNotAcceptAnyType()
125139
{
126140
$merge = new MergeClause();
@@ -132,4 +146,4 @@ public function testDoesNotAcceptAnyType()
132146

133147
$merge->toQuery();
134148
}
135-
}
149+
}

tests/Unit/Clauses/OptionalMatchTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use PHPUnit\Framework\TestCase;
2525
use TypeError;
26+
use WikibaseSolutions\CypherDSL\Assignment;
2627
use WikibaseSolutions\CypherDSL\Clauses\OptionalMatchClause;
2728
use WikibaseSolutions\CypherDSL\Patterns\Pattern;
2829
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
@@ -84,6 +85,17 @@ public function testAcceptsPathType()
8485
$match->toQuery();
8586
}
8687

88+
/**
89+
* @doesNotPerformAssertions
90+
*/
91+
public function testAcceptsAssignment()
92+
{
93+
$match = new OptionalMatchClause();
94+
$match->addPattern($this->getQueryConvertableMock(Assignment::class, "p = (a)-->(b)"));
95+
96+
$match->toQuery();
97+
}
98+
8799
public function testDoesNotAcceptAnyType()
88100
{
89101
$match = new OptionalMatchClause();
@@ -94,4 +106,4 @@ public function testDoesNotAcceptAnyType()
94106

95107
$match->toQuery();
96108
}
97-
}
109+
}

tests/Unit/QueryTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ public function testMatch()
226226
$this->assertSame("MATCH (m:Movie), (m:Movie)", $statement);
227227
}
228228

229+
/**
230+
* @doesNotPerformAssertions
231+
*/
232+
public function testMatchTypeAcceptance() {
233+
$assignment = $this->getQueryConvertableMock(Assignment::class, 'p = (a)-->(b)');
234+
$path = $this->getQueryConvertableMock(PathType::class, '(a)-->(b)');
235+
$node = $this->getQueryConvertableMock(NodeType::class, '(a)');
236+
237+
(new Query())->match([$assignment, $path, $node]);
238+
}
239+
229240
public function testMatchRejectsAnyType() {
230241
$m = $this->getQueryConvertableMock(AnyType::class, 'foo');
231242

@@ -284,6 +295,17 @@ public function testCreate()
284295
$this->assertSame("CREATE (m:Movie)-[:RELATED]->(b), (m:Movie)-[:RELATED]->(b)", $statement);
285296
}
286297

298+
/**
299+
* @doesNotPerformAssertions
300+
*/
301+
public function testCreateTypeAcceptance() {
302+
$assignment = $this->getQueryConvertableMock(Assignment::class, 'p = (a)-->(b)');
303+
$path = $this->getQueryConvertableMock(PathType::class, '(a)-->(b)');
304+
$node = $this->getQueryConvertableMock(NodeType::class, '(a)');
305+
306+
(new Query())->create([$assignment, $path, $node]);
307+
}
308+
287309
public function testCreateRejectsAnyType() {
288310
$m = $this->getQueryConvertableMock(AnyType::class, 'foo');
289311

@@ -359,6 +381,27 @@ public function testMerge()
359381
$this->assertSame("MERGE (m)->(b) ON CREATE DELETE (m:Movie) ON MATCH CREATE (m:Movie)", $statement);
360382
}
361383

384+
/**
385+
* @doesNotPerformAssertions
386+
*/
387+
public function testMergeTypeAcceptance() {
388+
$assignment = $this->getQueryConvertableMock(Assignment::class, 'p = (a)-->(b)');
389+
$path = $this->getQueryConvertableMock(PathType::class, '(a)-->(b)');
390+
$node = $this->getQueryConvertableMock(NodeType::class, '(a)');
391+
392+
(new Query())->merge($assignment);
393+
(new Query())->merge($path);
394+
(new Query())->merge($node);
395+
}
396+
397+
public function testMergeRejectsAnyType() {
398+
$m = $this->getQueryConvertableMock(AnyType::class, 'foo');
399+
400+
$this->expectException(TypeError::class);
401+
402+
(new Query())->optionalMatch([$m, $m]);
403+
}
404+
362405
public function testOptionalMatch()
363406
{
364407
$pattern = $this->getQueryConvertableMock(NodeType::class, "(m)");
@@ -372,8 +415,19 @@ public function testOptionalMatch()
372415
$this->assertSame("OPTIONAL MATCH (m), (m)", $statement);
373416
}
374417

418+
/**
419+
* @doesNotPerformAssertions
420+
*/
421+
public function testOptionalMatchTypeAcceptance() {
422+
$assignment = $this->getQueryConvertableMock(Assignment::class, 'p = (a)-->(b)');
423+
$path = $this->getQueryConvertableMock(PathType::class, '(a)-->(b)');
424+
$node = $this->getQueryConvertableMock(NodeType::class, '(a)');
425+
426+
(new Query())->optionalMatch([$assignment, $path, $node]);
427+
}
428+
375429
public function testOptionalMatchRejectsAnyType() {
376-
$m = $this->getQueryConvertableMock(AnyType::class, 'foo');
430+
$m = $this->getQueryConvertableMock(AnyType::class, 'foo');
377431

378432
$this->expectException(TypeError::class);
379433

0 commit comments

Comments
 (0)