Skip to content

Commit

Permalink
Add 'labeled' method to 'Node' class
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnvanwezel committed Dec 13, 2022
1 parent 8808a32 commit 27633fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Patterns/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Expressions\Label;
use WikibaseSolutions\CypherDSL\Expressions\Literals\Map;
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
Expand Down Expand Up @@ -81,6 +82,16 @@ public function getLabels(): array
return $this->labels;
}

/**
* Returns a label with the variable in this node.
*
* @param string ...$labels The labels to attach to the variable in this node
*/
public function labeled(string ...$labels): Label
{
return new Label($this->getVariable(), ...$labels);
}

/**
* @inheritDoc
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/Patterns/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use PHPUnit\Framework\TestCase;
use TypeError;
use WikibaseSolutions\CypherDSL\Expressions\Label;
use WikibaseSolutions\CypherDSL\Expressions\Literals\Float_;
use WikibaseSolutions\CypherDSL\Expressions\Literals\Integer;
use WikibaseSolutions\CypherDSL\Expressions\Literals\List_;
Expand Down Expand Up @@ -234,6 +235,22 @@ public function testRelationshipUni(): void
$this->assertSame("(:City)-[:LIVES_IN]-(:City {city: 'Amsterdam'})", $relationship->toQuery());
}

public function testLabeledSingleLabel(): void
{
$node = new Node();
$labeled = $node->labeled('German');

$this->assertEquals(new Label($node->getVariable(), 'German'), $labeled);
}

public function testLabeledMultipleLabels(): void
{
$node = new Node();
$labeled = $node->labeled('German', 'Swedish');

$this->assertEquals(new Label($node->getVariable(), 'German', 'Swedish'), $labeled);
}

public function provideOnlyLabelData(): array
{
return [
Expand Down

0 comments on commit 27633fa

Please sign in to comment.