Skip to content

Commit

Permalink
Allow callProcedure to take a string as function name
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnvanwezel committed Dec 8, 2022
1 parent a0d95d3 commit 864608b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,19 @@ public function call($query, $variables = []): self
/**
* Creates the CALL procedure clause.
*
* @param Procedure $procedure The procedure to call
* @param Procedure|string $procedure The procedure to call
* @param Alias|Alias[]|string|string[]|Variable|Variable[]|(Alias|string|Variable)[] $yields The result fields that should be returned (optional)
*
* @return $this
*
* @see https://neo4j.com/docs/cypher-manual/current/clauses/call/ Corresponding documentation on Neo4j.com
*/
public function callProcedure(Procedure $procedure, $yields = []): self
public function callProcedure($procedure, $yields = []): self
{
if (is_string($procedure)) {
$procedure = Procedure::raw($procedure, $yields);
}

if (!is_array($yields)) {
$yields = [$yields];
}
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/QueryCallProcedureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public function testProcedureWithMultipleYields(): void
$this->assertSame("CALL localtime() YIELD a, b", $statement->toQuery());
}

public function testCallProcedureString(): void
{
$statement = Query::new()->callProcedure('apoc.json');

$this->assertSame("CALL `apoc.json`()", $statement->toQuery());
}

public function testReturnsSameInstance(): void
{
$procedure = Procedure::localtime();
Expand Down

0 comments on commit 864608b

Please sign in to comment.