Skip to content

Commit e535ed5

Browse files
Fix failing test by adding additional method to mock
1 parent dbd7a8a commit e535ed5

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/Patterns/Node.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,27 @@ public function getName(): ?Variable
148148
return $this->variable;
149149
}
150150

151+
/**
152+
* Alias of Node::named().
153+
*
154+
* @param $variable
155+
* @return $this
156+
* @see Node::named()
157+
*
158+
*/
159+
public function setName($variable): self
160+
{
161+
return $this->named($variable);
162+
}
151163

152-
public function hasName(): bool {
153-
if (!isset($this->variable)) {
154-
return false;
155-
}
156-
return ($this->variable !== null);
164+
/**
165+
* Returns true if and only if this node has a name.
166+
*
167+
* @return bool
168+
*/
169+
public function hasName(): bool
170+
{
171+
return isset($this->variable);
157172
}
158173

159174
/**
@@ -186,6 +201,4 @@ public function toQuery(): string
186201

187202
return "($nodeInner)";
188203
}
189-
190-
191204
}

src/Query.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,13 @@ public function returning($expressions, bool $distinct = false): self
273273

274274
// check if expression is node, then replace with variable
275275
if ($expression instanceof Node) {
276-
print_r(["test" => $expression instanceof Node, "hasname" => $expression->hasName() === true, "expression" => $expression]);
277276
// check if Node has Name setted
278-
if (!($expression->hasName())) {
279-
$expression = $expression->named(uniqid())->getName();
280-
} else {
281-
$expression = $expression->getName();
277+
if (!$expression->hasName()) {
278+
$expression->setName(uniqid());
282279
}
283-
print_r(["test" => $expression instanceof AnyType, "expression" => $expression]);
284-
}
285280

281+
$expression = $expression->getName();
282+
}
286283

287284
$alias = is_integer($maybeAlias) ? "" : $maybeAlias;
288285
$returnClause->addColumn($expression, $alias);

tests/Unit/QueryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,10 @@ public function testBuild()
430430

431431
$this->assertSame("WITH foobar WHERE foobar", $statement);
432432

433-
$pathMock = $this->getQueryConvertableMock(Path::class, "(a)->(b)");
434433
$nodeMock = $this->getQueryConvertableMock(Node::class, "(a)");
434+
$nodeMock->method('getName')->willReturn($this->getQueryConvertableMock(Variable::class, 'a'));
435+
436+
$pathMock = $this->getQueryConvertableMock(Path::class, "(a)->(b)");
435437
$numeralMock = $this->getQueryConvertableMock(NumeralType::class, "12");
436438
$booleanMock = $this->getQueryConvertableMock(BooleanType::class, "a > b");
437439
$propertyMock = $this->getQueryConvertableMock(Property::class, "a.b");
@@ -453,7 +455,7 @@ public function testBuild()
453455
->with(["#" => $nodeMock])
454456
->build();
455457

456-
$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);
458+
$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);
457459
}
458460

459461
public function testBuildEmpty()

0 commit comments

Comments
 (0)