This repository was archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphWalker.php
More file actions
89 lines (68 loc) Β· 2.16 KB
/
GraphWalker.php
File metadata and controls
89 lines (68 loc) Β· 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace edno\Codeception;
use edno\GraphYEd\Loader as GraphLoader;
use Codeception\Test\Loader\LoaderInterface;
use Codeception\Test\Loader as TestLoader;
use Codeception\Lib\Di;
use Codeception\Exception\ModuleConfigException;
use Codeception\Exception\TestParseException;
use Codeception\Configuration;
class GraphWalker implements LoaderInterface
{
protected static $defaultSettings = [
'graphwalker' => [
'algorithm' => '',
'path' => ''
],
];
protected $settings = [];
protected $graph;
protected $parser;
protected $tests = [];
protected $path;
protected $di;
protected $algorithmClass;
protected $loader;
public function __construct($settings = [])
{
$this->settings = Configuration::mergeConfigs(self::$defaultSettings, $settings);
$this->algorithmClass = $this->settings['graphwalker']['algorithm'];
if ($this->algorithmClass == '') {
throw new ModuleConfigException(__CLASS__, 'Configuration setting "algorithm" is missing');
}
$this->path = $this->settings['graphwalker']['path'];
$this->di = new Di();
$this->parser = new GraphLoader();
$this->loader = new TestLoader(['path' => $this->path]);
}
public function loadTests($filename)
{
try {
$this->graph = $this->parser->loadContents(file_get_contents($filename));
$start = $this->graph->getVertices()->getVertexFirst();
$algorithm = $this->di->instantiate($this->algorithmClass, [$start]);
} catch (\Exception $e) {
throw new TestParseException(__CLASS__, $e->getMessage());
}
$path = $algorithm->getWalkTo($this->graph->getVertices()->getVertexLast())->getGraph();
$steps = $path->getVertices();
foreach ($steps as $step) {
$file = $this->path . $step->getAttribute('labels')[0];
$this->loader->loadTest($file);
}
$this->settings['exclude'][] = $filename;
$this->tests = $this->loader->getTests();
}
public function getTests()
{
return $this->tests;
}
public function getPattern()
{
return '~\.graphml$~';
}
public function getGraph()
{
return $this->graph;
}
}