Skip to content

Commit 25a1225

Browse files
committed
wip
1 parent 750cd52 commit 25a1225

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

src/Helper/ToCypherHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function propertyArrayToCypherPropertyString(array $properties): s
3838
$resultParts[] = sprintf(
3939
"%s: '%s'",
4040
$name,
41-
EscapeHelper::escapeCharacter("'", $value)
41+
EscapeHelper::escapeCharacter("'", (string) $value)
4242
);
4343
}
4444

src/Type/Node.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function addRelation(RelationInterface $relation): self
8989
throw new InvalidArgumentException("Adding a relation to a node requires that either the start node or the end node must be the same as the node itself.");
9090
}
9191

92-
$this->relations[$ownIdentifyingString] = $relation;
92+
$this->relations[ToCypherHelper::relationToIdentifyingCypherString($relation)] = $relation;
9393

9494
return $this;
9595
}

tests/Type/NodeTest.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Syndesi\CypherDataStructures\Tests\Type;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Syndesi\CypherDataStructures\Type\Node;
9+
use Syndesi\CypherDataStructures\Type\Relation;
10+
11+
class NodeTest extends TestCase
12+
{
13+
public function testNodeIsInitiallyEmpty(): void
14+
{
15+
$node = new Node();
16+
$this->assertEmpty($node->getLabels());
17+
$this->assertEmpty($node->getProperties());
18+
$this->assertEmpty($node->getIdentifiers());
19+
$this->assertEmpty($node->getRelations());
20+
}
21+
22+
public function testNodeLabels(): void
23+
{
24+
$node = new Node();
25+
26+
$node->addLabel('labelA');
27+
$this->assertCount(1, $node->getLabels());
28+
$this->assertSame('labelA', $node->getLabels()[0]);
29+
$this->assertTrue($node->hasLabel('labelA'));
30+
31+
$labels = ['labelB', 'labelC', 'labelD'];
32+
$node->addLabels($labels);
33+
$this->assertCount(4, $node->getLabels());
34+
35+
$node->removeLabel('labelC');
36+
$this->assertCount(3, $node->getLabels());
37+
$this->assertFalse($node->hasLabel('labelC'));
38+
39+
$node->removeLabels();
40+
$this->assertEmpty($node->getLabels());
41+
}
42+
43+
public function testNodeRelations(): void
44+
{
45+
$node = (new Node())
46+
->addLabel('startNode')
47+
->addProperty('id', 100)
48+
->addIdentifier('id');
49+
50+
$relation = (new Relation())
51+
->setStartNode($node)
52+
->setEndNode(new Node());
53+
54+
$this->assertEmpty($node->getRelations());
55+
56+
$node->addRelation($relation);
57+
$this->assertCount(1, $node->getRelations());
58+
$this->assertSame($relation, $node->getRelations()[0]);
59+
$this->assertTrue($node->hasRelation($relation));
60+
61+
$relations = [
62+
(new Relation())
63+
->setStartNode($node)
64+
->setEndNode(
65+
(new Node())
66+
->addLabel('otherNode')
67+
->addProperty('id', 101)
68+
->addIdentifier('id')
69+
)
70+
->addProperty('id', 201)
71+
->addIdentifier('id'),
72+
(new Relation())
73+
->setStartNode($node)
74+
->setEndNode(
75+
(new Node())
76+
->addLabel('otherNode')
77+
->addProperty('id', 102)
78+
->addIdentifier('id')
79+
)
80+
->addProperty('id', 202)
81+
->addIdentifier('id'),
82+
];
83+
84+
$this->assertFalse($node->hasRelation($relations[0]));
85+
$node->addRelations($relations);
86+
$this->assertCount(3, $node->getRelations());
87+
88+
$node->removeRelation($relations[1]);
89+
$this->assertCount(2, $node->getRelations());
90+
91+
$node->removeRelations();
92+
$this->assertEmpty($node->getRelations());
93+
}
94+
}

0 commit comments

Comments
 (0)