|
5 | 5 | namespace Syndesi\CypherDataStructures\Tests\Type;
|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase;
|
| 8 | +use Syndesi\CypherDataStructures\Exception\InvalidArgumentException; |
8 | 9 | use Syndesi\CypherDataStructures\Type\Node;
|
9 | 10 | use Syndesi\CypherDataStructures\Type\Relation;
|
10 | 11 |
|
@@ -91,4 +92,59 @@ public function testNodeRelations(): void
|
91 | 92 | $node->removeRelations();
|
92 | 93 | $this->assertEmpty($node->getRelations());
|
93 | 94 | }
|
| 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 | + } |
94 | 150 | }
|
0 commit comments