/** * Create edges between versions graph * * @param Graph $graph * @param string $className */ private function createEdges(Graph $graph, $className) { $migrationsAnnotations = $this->reader->getClassMigrationMethodInfo($className); $parentVertex = $graph->hasVertex($className) ? $graph->getVertex($className) : $graph->createVertex($className); foreach ($migrationsAnnotations as $migrationsAnnotation) { if ($migrationsAnnotation->annotation->from) { $fromClass = $migrationsAnnotation->annotation->from; $fromVertex = $graph->hasVertex($fromClass) ? $graph->getVertex($fromClass) : $graph->createVertex($fromClass); if (!$parentVertex->hasEdgeTo($fromVertex)) { $edge = $fromVertex->createEdgeTo($parentVertex); $this->annotations[$this->getEdgeId($edge)] = $migrationsAnnotation; $this->createEdges($graph, $fromClass); } } if ($migrationsAnnotation->annotation->to) { $toClass = $migrationsAnnotation->annotation->to; $fromVertex = $graph->hasVertex($toClass) ? $graph->getVertex($toClass) : $graph->createVertex($toClass); if (!$parentVertex->hasEdgeTo($fromVertex)) { $edge = $parentVertex->createEdgeTo($fromVertex); $this->annotations[$this->getEdgeId($edge)] = $migrationsAnnotation; $this->createEdges($graph, $toClass); } } } }
public function testAddsStatesToGraph() { $state = new State('first'); $stateCollection = new StateCollection(); $stateCollection->addState($state); $secondState = new State('second'); $state->addTransition(new Transition($secondState)); $graph = new Graph(); $builder = new GraphBuilder($graph); $builder->addStateCollection($stateCollection); $this->assertTrue($graph->hasVertex('first')); $this->assertTrue($graph->hasVertex('second')); }
/** * Build out-tree graph from defined Processes and their relations. * * @return OutTree */ public function buildTree() { if (!$this->tree) { $root = $this->graph->createVertex(0); // Create edges directed from the root node foreach ($this->processes as $processClassName => $processObject) { $vertex = $this->graph->getVertex($processClassName); if (!$processObject->delayMinutes) { // process doesn't depend on anything => link it to the root node $root->createEdgeTo($vertex)->setWeight(0); } else { // link process to its dependency // Throw error if dependency is to not existing vertex if (!$this->graph->hasVertex($processObject->delayAfter)) { throw new \InvalidArgumentException(sprintf('Testcase "%s" has @delayAfter dependency on "%s", but this testcase was not defined.', $processClassName, $processObject->delayAfter)); } $this->graph->getVertex($processObject->delayAfter)->createEdgeTo($vertex)->setWeight($processObject->delayMinutes); } } } $this->tree = new OutTree($this->graph); if (!$this->tree->isTree()) { throw new \InvalidArgumentException(sprintf('Cannot build tree graph from tests dependencies. Probably some cyclic dependency is present.')); } return $this->tree; }
exit; } $parents = str_replace($id, '', $parents); $parents = explode(',', $parents); $parents = array_filter($parents); if ($sequence->hasGraph()) { $graph = $sequence->getUnSerializeGraph(); } else { $graph = new Graph(); } switch ($type) { case 'session': $type = SequenceResource::SESSION_TYPE; $sessionInfo = api_get_session_info($id); $name = $sessionInfo['name']; if ($graph->hasVertex($id)) { $main = $graph->getVertex($id); } else { $main = $graph->createVertex($id); } foreach ($parents as $parentId) { if ($graph->hasVertex($parentId)) { $parent = $graph->getVertex($parentId); if (!$parent->hasEdgeTo($main)) { $parent->createEdgeTo($main); } } else { $parent = $graph->createVertex($parentId); $parent->createEdgeTo($main); } }
public function testHasVertex() { $graph = new Graph(); $graph->createVertex(1); $graph->createVertex('string'); // check integer IDs $this->assertFalse($graph->hasVertex(2)); $this->assertTrue($graph->hasVertex(1)); // check string IDs $this->assertFalse($graph->hasVertex('non-existant')); $this->assertTrue($graph->hasVertex('string')); // integer IDs can also be checked as string IDs $this->assertTrue($graph->hasVertex('1')); }