/** * Adds a node to the nodes collection * * @param Node $node * @return bool * @throws SchemaDefinitionException */ public function addNode(Node $node) { foreach ($this->nodes as $n) { if ($n->getIdentifier() === $node->getIdentifier()) { throw new SchemaDefinitionException(sprintf('The node with Identifier "%s" has already been declared', $node->getIdentifier())); } } return $this->nodes->add($node); }
/** * @param NodeDefinition $node * @param null|int $seed * @return ObjectCollection */ public function processNodeDefinition(NodeDefinition $node, $seed) { $collection = new ObjectCollection(); for ($i = 0; $i < $node->getAmount(); $i++) { $id = $this->faker->generate('uuid', [], null, true); $n = new Node($id); $n->addLabels($node->getLabels()->toArray()); foreach ($node->getProperties() as $property) { $n->addProperty($property->getName(), $this->getFakeData($property, $seed)); } $collection->add($n); $this->nodes->add($n); } $this->nodesByIdentifier->set($node->getIdentifier(), $collection); }
function it_should_throw_error_when_adding_nodes_with_same_identifier(Node $node) { $node->getIdentifier()->willReturn('person'); $this->addNode($node); $this->shouldThrow('Neoxygen\\Neogen\\Exception\\SchemaDefinitionException')->duringAddNode($node); }