Skip to content

Commit 1fb3e47

Browse files
committed
wip
1 parent 030a660 commit 1fb3e47

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/Type/NodeTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Syndesi\CypherDataStructures\Tests\Type;
66

77
use PHPUnit\Framework\TestCase;
8+
use Syndesi\CypherDataStructures\Exception\InvalidArgumentException;
89
use Syndesi\CypherDataStructures\Type\Node;
910
use Syndesi\CypherDataStructures\Type\Relation;
1011

@@ -91,4 +92,59 @@ public function testNodeRelations(): void
9192
$node->removeRelations();
9293
$this->assertEmpty($node->getRelations());
9394
}
95+
96+
public function testExceptionOnMissingStartNode(): void
97+
{
98+
$node = new Node();
99+
$relation = (new Relation())
100+
->setEndNode(new Node());
101+
$this->expectExceptionMessage('Start node must be set');
102+
$this->expectException(InvalidArgumentException::class);
103+
$node->addRelation($relation);
104+
}
105+
106+
public function testExceptionOnMissingEndNode(): void
107+
{
108+
$node = new Node();
109+
$relation = (new Relation())
110+
->setStartNode(new Node());
111+
$this->expectExceptionMessage('End node must be set');
112+
$this->expectException(InvalidArgumentException::class);
113+
$node->addRelation($relation);
114+
}
115+
116+
public function testExceptionOnRelationIsNotConnectedToNode(): void
117+
{
118+
$node = (new Node())
119+
->addProperty('id', 1234)
120+
->addIdentifier('id');
121+
$relation = (new Relation())
122+
->setStartNode(new Node())
123+
->setEndNode(new Node());
124+
$this->expectExceptionMessage('Adding a relation to a node requires that either the start node or the end node must be the same as the node itself.');
125+
$this->expectException(InvalidArgumentException::class);
126+
$node->addRelation($relation);
127+
}
128+
129+
public function testToString(): void
130+
{
131+
$node = (new Node())
132+
->addLabels(['LabelA', 'LabelZ', 'LabelC', 'discouraged Style'])
133+
->addProperty('id', 123)
134+
->addIdentifier('id');
135+
// todo fix backticks in ToCypherHelper class
136+
$this->assertSame("(:LabelA:LabelC:LabelZ:discouraged Style {id: '123'})", (string) $node);
137+
}
138+
139+
public function testIsEqualTo(): void
140+
{
141+
$node = (new Node())
142+
->addLabel('Node')
143+
->addProperty('id', 123)
144+
->addIdentifier('id');
145+
$this->assertFalse($node->isEqualTo(123));
146+
$this->assertFalse($node->isEqualTo(new Node()));
147+
$this->assertTrue($node->isEqualTo($node));
148+
$this->assertTrue($node->isEqualTo(clone $node));
149+
}
94150
}

0 commit comments

Comments
 (0)