|
| 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