diff --git a/src/Patterns/Node.php b/src/Patterns/Node.php index ffb44a3..6ab73df 100644 --- a/src/Patterns/Node.php +++ b/src/Patterns/Node.php @@ -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; @@ -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 */ diff --git a/tests/unit/Patterns/NodeTest.php b/tests/unit/Patterns/NodeTest.php index fed04ec..85b71d7 100644 --- a/tests/unit/Patterns/NodeTest.php +++ b/tests/unit/Patterns/NodeTest.php @@ -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_; @@ -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 [