Skip to content

Commit 69cd5c7

Browse files
author
Wout Gevaert
committed
Use variables instead of nodes when testing delete clauses.
1 parent 2a45374 commit 69cd5c7

File tree

2 files changed

+45
-41
lines changed

2 files changed

+45
-41
lines changed

tests/Unit/Clauses/DeleteClauseTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use WikibaseSolutions\CypherDSL\Clauses\DeleteClause;
2727
use WikibaseSolutions\CypherDSL\Tests\Unit\TestHelper;
2828
use WikibaseSolutions\CypherDSL\Types\AnyType;
29-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
29+
use WikibaseSolutions\CypherDSL\Variable;
3030

3131
/**
3232
* @covers \WikibaseSolutions\CypherDSL\Clauses\DeleteClause
@@ -40,69 +40,69 @@ public function testEmptyClause(): void
4040
$delete = new DeleteClause();
4141

4242
$this->assertSame("", $delete->toQuery());
43-
$this->assertEquals([], $delete->getNodes());
43+
$this->assertEquals([], $delete->getVariables());
4444
$this->assertFalse($delete->detachesDeletion());
4545
}
4646

47-
public function testSingleNode(): void
47+
public function testSingleVariable(): void
4848
{
4949
$delete = new DeleteClause();
50-
$node = $this->getQueryConvertableMock(NodeType::class, "(a)");
50+
$variable = $this->getQueryConvertableMock(Variable::class, "a");
5151

52-
$delete->addNode($node);
52+
$delete->addVariable($variable);
5353

54-
$this->assertSame("DELETE (a)", $delete->toQuery());
55-
$this->assertEquals([$node], $delete->getNodes());
54+
$this->assertSame("DELETE a", $delete->toQuery());
55+
$this->assertEquals([$variable], $delete->getVariables());
5656
$this->assertFalse($delete->detachesDeletion());
5757
}
5858

59-
public function testMultipleNodes(): void
59+
public function testMultipleVariables(): void
6060
{
6161
$delete = new DeleteClause();
6262

63-
$a = $this->getQueryConvertableMock(NodeType::class, "(a)");
64-
$b = $this->getQueryConvertableMock(NodeType::class, "(b)");
63+
$a = $this->getQueryConvertableMock(Variable::class, "a");
64+
$b = $this->getQueryConvertableMock(Variable::class, "b");
6565

66-
$delete->addNode($a);
67-
$delete->addNode($b);
66+
$delete->addVariable($a);
67+
$delete->addVariable($b);
6868

69-
$this->assertSame("DELETE (a), (b)", $delete->toQuery());
70-
$this->assertEquals([$a, $b], $delete->getNodes());
69+
$this->assertSame("DELETE a, b", $delete->toQuery());
70+
$this->assertEquals([$a, $b], $delete->getVariables());
7171
$this->assertFalse($delete->detachesDeletion());
7272
}
7373

7474
public function testDetachDelete(): void
7575
{
7676
$delete = new DeleteClause();
77-
$pattern = $this->getQueryConvertableMock(NodeType::class, "(a)");
77+
$variable = $this->getQueryConvertableMock(Variable::class, "a");
7878

79-
$delete->addNode($pattern);
79+
$delete->addVariable($variable);
8080
$delete->setDetach(true);
8181

82-
$this->assertSame("DETACH DELETE (a)", $delete->toQuery());
83-
$this->assertEquals([$pattern], $delete->getNodes());
82+
$this->assertSame("DETACH DELETE a", $delete->toQuery());
83+
$this->assertEquals([$variable], $delete->getVariables());
8484
$this->assertTrue($delete->detachesDeletion());
8585
}
8686

87-
public function testAcceptsNodeType(): void
87+
public function testAcceptsVariable(): void
8888
{
8989
$delete = new DeleteClause();
90-
$pattern = $this->getQueryConvertableMock(NodeType::class, "(a)");
90+
$variable = $this->getQueryConvertableMock(Variable::class, "a");
9191

92-
$delete->addNode($pattern);
92+
$delete->addVariable($variable);
9393
$delete->toQuery();
94-
$this->assertEquals([$pattern], $delete->getNodes());
94+
$this->assertEquals([$variable], $delete->getVariables());
9595
$this->assertFalse($delete->detachesDeletion());
9696
}
9797

9898
public function testDoesNotAcceptAnyType(): void
9999
{
100100
$delete = new DeleteClause();
101-
$pattern = $this->getQueryConvertableMock(AnyType::class, "(a)");
101+
$variable = $this->getQueryConvertableMock(AnyType::class, "a");
102102

103103
$this->expectException(TypeError::class);
104104

105-
$delete->addNode($pattern);
105+
$delete->addVariable($variable);
106106
$delete->toQuery();
107107
}
108108
}

tests/Unit/QueryTest.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,15 @@ public function testCreateRejectsAnyType(): void
317317

318318
public function testDelete(): void
319319
{
320-
$m = $this->getQueryConvertableMock(NodeType::class, "(m:Movie)");
320+
$m = $this->getQueryConvertableMock(Variable::class, "m");
321321

322322
$statement = (new Query())->delete($m)->build();
323323

324-
$this->assertSame("DELETE (m:Movie)", $statement);
324+
$this->assertSame("DELETE m", $statement);
325325

326326
$statement = (new Query())->delete([$m, $m])->build();
327327

328-
$this->assertSame("DELETE (m:Movie), (m:Movie)", $statement);
328+
$this->assertSame("DELETE m, m", $statement);
329329
}
330330

331331
public function testDeleteRejectsAnyType(): void
@@ -339,15 +339,15 @@ public function testDeleteRejectsAnyType(): void
339339

340340
public function testDetachDelete(): void
341341
{
342-
$m = $this->getQueryConvertableMock(NodeType::class, "(m:Movie)");
342+
$m = $this->getQueryConvertableMock(Variable::class, "m");
343343

344344
$statement = (new Query())->detachDelete($m)->build();
345345

346-
$this->assertSame("DETACH DELETE (m:Movie)", $statement);
346+
$this->assertSame("DETACH DELETE m", $statement);
347347

348348
$statement = (new Query())->detachDelete([$m, $m])->build();
349349

350-
$this->assertSame("DETACH DELETE (m:Movie), (m:Movie)", $statement);
350+
$this->assertSame("DETACH DELETE m, m", $statement);
351351
}
352352

353353
public function testDetachDeleteRejectsAnyType(): void
@@ -609,6 +609,7 @@ public function testBuild(): void
609609
$nodeMock = $this->getQueryConvertableMock(Node::class, "(a)");
610610
$nodeMock->method('getName')->willReturn($this->getQueryConvertableMock(Variable::class, 'a'));
611611

612+
$variableMock = $this->getQueryConvertableMock(Variable::class, "a");
612613
$pathMock = $this->getQueryConvertableMock(Path::class, "(a)->(b)");
613614
$numeralMock = $this->getQueryConvertableMock(NumeralType::class, "12");
614615
$booleanMock = $this->getQueryConvertableMock(BooleanType::class, "a > b");
@@ -619,8 +620,8 @@ public function testBuild(): void
619620
->returning(["#" => $nodeMock])
620621
->create([$pathMock, $nodeMock])
621622
->create($pathMock)
622-
->delete([$nodeMock, $nodeMock])
623-
->detachDelete([$nodeMock, $nodeMock])
623+
->delete([$variableMock, $variableMock])
624+
->detachDelete([$variableMock, $variableMock])
624625
->limit($numeralMock)
625626
->merge($nodeMock)
626627
->optionalMatch([$nodeMock, $nodeMock])
@@ -631,7 +632,7 @@ public function testBuild(): void
631632
->with(["#" => $nodeMock])
632633
->build();
633634

634-
$this->assertSame("MATCH (a)->(b), (a) RETURN a AS `#` CREATE (a)->(b), (a) CREATE (a)->(b) DELETE (a), (a) DETACH DELETE (a), (a) LIMIT 12 MERGE (a) OPTIONAL MATCH (a), (a) ORDER BY a.b, a.b DESCENDING REMOVE a.b WHERE a > b WITH a AS `#`", $statement);
635+
$this->assertSame("MATCH (a)->(b), (a) RETURN a AS `#` CREATE (a)->(b), (a) CREATE (a)->(b) DELETE a, a DETACH DELETE a, a LIMIT 12 MERGE (a) OPTIONAL MATCH (a), (a) ORDER BY a.b, a.b DESCENDING REMOVE a.b WHERE a > b WITH a AS `#`", $statement);
635636
}
636637

637638
public function testBuildEmpty(): void
@@ -839,21 +840,24 @@ public function testWikiExamples(): void
839840
* @see https://gitlab.wikibase.nl/community/libraries/php-cypher-dsl/-/wikis/Usage/Clauses/DELETE-clause
840841
*/
841842

842-
$tom = Query::node("Person")->named("tom");
843+
$tomVar = Query::variable('tom');
844+
$tomNode = Query::node("Person")->named($tomVar)->withProperty('name', Query::literal('tom'));
843845

844-
$statement = Query::new()
845-
->delete($tom)
846+
847+
$statement = Query::new()->match($tomNode)
848+
->delete($tomVar)
846849
->build();
847850

848-
$this->assertSame("DELETE (tom:Person)", $statement);
851+
$this->assertSame("MATCH (tom:Person {name: 'tom'}) DELETE tom", $statement);
849852

850-
$tom = Query::node("Person")->named("tom");
853+
$tomVar = Query::variable('tom');
854+
$tomNode = Query::node("Person")->named($tomVar)->withProperty('name', Query::literal('tom'));
851855

852-
$statement = Query::new()
853-
->detachDelete($tom)
856+
$statement = Query::new()->match($tomNode)
857+
->detachDelete($tomVar)
854858
->build();
855859

856-
$this->assertSame("DETACH DELETE (tom:Person)", $statement);
860+
$this->assertSame("MATCH (tom:Person {name: 'tom'}) DETACH DELETE tom", $statement);
857861

858862
/*
859863
* @see https://gitlab.wikibase.nl/community/libraries/php-cypher-dsl/-/wikis/Usage/Clauses/LIMIT-clause

0 commit comments

Comments
 (0)