Esempio n. 1
0
 /**
  * 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;
 }
 public function testCreateFromProcess()
 {
     $process = new Process('test', 'fromNode', [new State('fromNode', [new Event('eventName', 'targetNode', 'errorNode')]), new State('targetNode'), new State('errorNode')]);
     $document = Document::fromProcess($process);
     $this->assertEquals('digraph test {dpi="75";pad="1";fontname="Courier";nodesep="1";rankdir="TD";ranksep="0.5";node[label="fromNode"]{ node_fromNode };node[label="targetNode"]{ node_targetNode };node[label="errorNode"]{ node_errorNode };edge[label=" eventName",color="#66FF00"] node_fromNode -> node_targetNode;edge[label=" eventName",color="#FF2200"] node_fromNode -> node_errorNode;}', (string) $document);
 }