public function testAddEdge() { $document = new Document('test'); $document->addNode(new Node('fromNode')); $document->addNode(new Node('toNode')); $document->addEdge(new Edge('fromNode', 'toNode', 'eventName')); $this->assertEquals('digraph test {dpi="75";pad="1";fontname="Courier";nodesep="1";rankdir="TD";ranksep="0.5";node[label="fromNode"]{ node_fromNode };node[label="toNode"]{ node_toNode };edge[label=" eventName"] node_fromNode -> node_toNode;}', (string) $document); }
/** * Create document from Process * * @param Process $process * * @return Document */ public static function fromProcess(Process $process) : Document { $document = new Document($process->name()); foreach ($process->states() as $state) { $document->addNode(new Node($state->name())); foreach ($state->events() as $event) { $transitions = array_filter(['target' => $event->targetState(), 'error' => $event->errorState()]); foreach ($transitions as $type => $target) { switch ($type) { case 'target': $document->addEdge(Edge::targetTransition($state->name(), $target, $event->name())); break; case 'error': $document->addEdge(Edge::errorTransition($state->name(), $target, $event->name())); break; default: $document->addEdge(new Edge($state->name(), $target, $event->name())); } } } } return $document; }