|
| 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 RelationTest extends TestCase |
| 12 | +{ |
| 13 | + public function testRelationIsInitiallyEmpty(): void |
| 14 | + { |
| 15 | + $relation = new Relation(); |
| 16 | + $this->assertNull($relation->getType()); |
| 17 | + $this->assertEmpty($relation->getProperties()); |
| 18 | + $this->assertEmpty($relation->getIdentifiers()); |
| 19 | + $this->assertNull($relation->getStartNode()); |
| 20 | + $this->assertNull($relation->getEndNode()); |
| 21 | + } |
| 22 | + |
| 23 | + public function testRelationType(): void |
| 24 | + { |
| 25 | + $relation = new Relation(); |
| 26 | + $relation->setType('SOME_TYPE'); |
| 27 | + $this->assertSame('SOME_TYPE', $relation->getType()); |
| 28 | + $relation->setType(null); |
| 29 | + $this->assertNull($relation->getType()); |
| 30 | + } |
| 31 | + |
| 32 | + public function testRelationStartNode(): void |
| 33 | + { |
| 34 | + $relation = new Relation(); |
| 35 | + $this->assertNull($relation->getStartNode()); |
| 36 | + $node = (new Node()) |
| 37 | + ->addLabel('Node') |
| 38 | + ->addProperty('id', 123) |
| 39 | + ->addIdentifier('id'); |
| 40 | + $relation->setStartNode($node); |
| 41 | + $this->assertSame($node, $relation->getStartNode()); |
| 42 | + $relation->setStartNode(null); |
| 43 | + $this->assertNull($relation->getStartNode()); |
| 44 | + } |
| 45 | + |
| 46 | + public function testRelationEndNode(): void |
| 47 | + { |
| 48 | + $relation = new Relation(); |
| 49 | + $this->assertNull($relation->getEndNode()); |
| 50 | + $node = (new Node()) |
| 51 | + ->addLabel('Node') |
| 52 | + ->addProperty('id', 123) |
| 53 | + ->addIdentifier('id'); |
| 54 | + $relation->setEndNode($node); |
| 55 | + $this->assertSame($node, $relation->getEndNode()); |
| 56 | + $relation->setEndNode(null); |
| 57 | + $this->assertNull($relation->getEndNode()); |
| 58 | + } |
| 59 | + |
| 60 | + public function testToString(): void |
| 61 | + { |
| 62 | + $relation = (new Relation()) |
| 63 | + ->setType('SOME_TYPE') |
| 64 | + ->addProperty('id', 123) |
| 65 | + ->addProperty('hello', 'world') |
| 66 | + ->addIdentifier('id') |
| 67 | + ->setStartNode( |
| 68 | + (new Node()) |
| 69 | + ->addLabel('StartNode') |
| 70 | + ) |
| 71 | + ->setEndNode( |
| 72 | + (new Node()) |
| 73 | + ->addLabel('EndNode') |
| 74 | + ); |
| 75 | + $this->assertSame("(:StartNode)-[:SOME_TYPE {hello: 'world', id: '123'}]->(:EndNode)", (string) $relation); |
| 76 | + } |
| 77 | + |
| 78 | + public function testIsEqualTo(): void |
| 79 | + { |
| 80 | + $relation = (new Relation()) |
| 81 | + ->setType('SOME_TYPE') |
| 82 | + ->addProperty('id', 123) |
| 83 | + ->addProperty('hello', 'world') |
| 84 | + ->addIdentifier('id') |
| 85 | + ->setStartNode( |
| 86 | + (new Node()) |
| 87 | + ->addLabel('StartNode') |
| 88 | + ) |
| 89 | + ->setEndNode( |
| 90 | + (new Node()) |
| 91 | + ->addLabel('EndNode') |
| 92 | + ); |
| 93 | + $this->assertFalse($relation->isEqualTo(123)); |
| 94 | + $this->assertFalse($relation->isEqualTo( |
| 95 | + (new Relation()) |
| 96 | + ->setStartNode(new Node()) |
| 97 | + ->setEndNode(new Node()) |
| 98 | + )); |
| 99 | + $this->assertTrue($relation->isEqualTo($relation)); |
| 100 | + $this->assertTrue($relation->isEqualTo(clone $relation)); |
| 101 | + } |
| 102 | +} |
0 commit comments