function it_should_throw_error_when_creating_duplicated_relationships(Relationship $relationship) { $relationship->getType()->willReturn('RELATES'); $relationship->getStartNode()->willReturn('person'); $relationship->getEndNode()->willReturn('company'); $this->addRelationship($relationship); $this->shouldThrow('Neoxygen\\Neogen\\Exception\\SchemaDefinitionException')->duringAddRelationship($relationship); }
/** * Adds a relationship to the relationship collection * * @param Relationship $relationship * @return bool * @throws SchemaDefinitionException */ public function addRelationship(Relationship $relationship) { foreach ($this->relationships as $rel) { if ($rel->getType() === $relationship->getType() && $rel->getStartNode() === $relationship->getStartNode() && $rel->getEndNode() === $relationship->getEndNode()) { throw new SchemaDefinitionException(sprintf('There is already a relationship declared with TYPE "%s" and STARTNODE "%s" and ENDNODE "%s"', $relationship->getType(), $relationship->getStartNode(), $relationship->getEndNode())); } } return $this->relationships->add($relationship); }
function it_should_define_percentage_of_target_nodes(ObjectCollection $collection, Relationship $relationship) { $collection->count()->willReturn(100); $relationship->hasPercentage()->willReturn(false); $relationship->getEndNode()->willReturn('person'); $this->getTargetNodesCount($relationship, $collection)->shouldBe(60); $collection->count()->willReturn(1); $relationship->hasPercentage()->willReturn(false); $relationship->getEndNode()->willReturn('person'); $this->getTargetNodesCount($relationship, $collection)->shouldBe(1); $collection->count()->willReturn(1000); $relationship->hasPercentage()->willReturn(false); $this->getTargetNodesCount($relationship, $collection)->shouldBe(200); $collection->count()->willReturn(100); $relationship->hasPercentage()->willReturn(true); $relationship->getPercentage()->willReturn(65); $this->getTargetNodesCount($relationship, $collection)->shouldBe(65); $collection->count()->willReturn(1000); $relationship->hasPercentage()->willReturn(true); $relationship->getPercentage()->willReturn(45); $this->getTargetNodesCount($relationship, $collection)->shouldBe(450); }
/** * @param RelationshipDefinition $relationship * @param ObjectCollection $targetNodes * @return int */ public function getTargetNodesCount(RelationshipDefinition $relationship, ObjectCollection $targetNodes) { $targetCount = $targetNodes->count(); if ($relationship->hasPercentage()) { $pct = $relationship->getPercentage(); } else { $pct = $targetCount <= 100 ? 60 : 20; } $percentage = $pct / 100; $count = round($targetCount * $percentage); return (int) $count; }