1 : <?php
2 :
3 : /**
4 : * XSLT Benchmarking
5 : * @link https://github.com/masicek/XSLT-Benchmarking
6 : * @author Viktor Mašíček <viktor@masicek.net>
7 : * @license "New" BSD License
8 : */
9 :
10 : namespace XSLTBenchmarking\TestsRunner;
11 :
12 : require_once LIBS . '/PhpPath/PhpPath.min.php';
13 : require_once ROOT . '/Exceptions.php';
14 : require_once ROOT . '/Printer.php';
15 :
16 : use PhpPath\P;
17 : use XSLTBenchmarking\Printer;
18 :
19 : /**
20 : * Runner
21 : *
22 : * @author Viktor Mašíček <viktor@masicek.net>
23 : */
24 : class Runner
25 : {
26 :
27 :
28 : /**
29 : * Factory class for making new objects
30 : *
31 : * @var \XSLTBenchmarking\Factory
32 : */
33 : private $factory;
34 :
35 : /**
36 : * Object for reading params of tests
37 : *
38 : * @var \XSLTBenchmarking\TestsRunner\Params
39 : */
40 : private $params;
41 :
42 : /**
43 : * Object for runnig one test on all processors
44 : *
45 : * @var \XSLTBenchmarking\TestsRunner\TestRunner
46 : */
47 : private $testRunner;
48 :
49 : /**
50 : * Object for printing reports
51 : *
52 : * @var \XSLTBenchmarking\Reports\Printer
53 : */
54 : private $reportsPrinter;
55 :
56 : /**
57 : * Root directory of generated tests
58 : *
59 : * @var string
60 : */
61 : private $testsDirectory;
62 :
63 : /**
64 : * Tests for generating
65 : *
66 : * @var array of Test
67 : */
68 : private $tests = array();
69 :
70 :
71 : /**
72 : * Object configuration
73 : *
74 : * @param \XSLTBenchmarking\Factory $factory Factory class for making new objects
75 : * @param \XSLTBenchmarking\TestsRunner\Params $params Object for reading params of tests
76 : * @param \XSLTBenchmarking\TestsRunner\TestRunner $testRunner Object for runnig one test on all processors
77 : * @param type $testsDirectory The root directory of all generated tests
78 : */
79 : public function __construct(
80 : \XSLTBenchmarking\Factory $factory,
81 : \XSLTBenchmarking\TestsRunner\Params $params,
82 : \XSLTBenchmarking\TestsRunner\TestRunner $testRunner,
83 : \XSLTBenchmarking\Reports\Printer $reportPrinter,
84 : $testsDirectory
85 : )
86 : {
87 2 : $testsDirectory = P::mcd($testsDirectory);
88 :
89 1 : $this->factory = $factory;
90 1 : $this->params = $params;
91 1 : $this->testRunner = $testRunner;
92 1 : $this->reportsPrinter = $reportPrinter;
93 1 : $this->testsDirectory = $testsDirectory;
94 1 : }
95 :
96 :
97 : /**
98 : * Register defined tests for runnig
99 : *
100 : * @param string $testDirectory The subdirectory of the root directory
101 : * of tests containing test for running
102 : * @param string $paramsFiles File defined test
103 : *
104 : * @return void
105 : */
106 : public function addTest($testDirectory, $testParamsFile = '__params.xml')
107 : {
108 4 : $testParamsPath = P::mcf($this->testsDirectory, $testDirectory, $testParamsFile);
109 :
110 2 : $this->params->setFile($testParamsPath);
111 2 : $name = $this->params->getName();
112 :
113 2 : if (isset($this->tests[$name]))
114 2 : {
115 1 : throw new \XSLTBenchmarking\CollisionException('Duplicate name of test "' . $name . '"');
116 : }
117 :
118 2 : $test = $this->factory->getTestsRunnerTest($name);
119 2 : $test->setTemplatePath($this->params->getTemplatePath());
120 2 : $test->addCouplesPaths($this->params->getCouplesPaths());
121 :
122 2 : $this->tests[$name] = $test;
123 2 : }
124 :
125 :
126 : /**
127 : * Return defined tests for running
128 : *
129 : * @return array
130 : */
131 : public function getTests()
132 : {
133 1 : return $this->tests;
134 : }
135 :
136 :
137 : /**
138 : * Run all added tests and print reports
139 : *
140 : * @param bool $verbose Print information about each run test
141 : *
142 : * @return int Number of run tests
143 : */
144 : public function runAll($verbose = FALSE)
145 : {
146 2 : $testCount = count($this->tests);
147 2 : $testsRun = 0;
148 2 : foreach ($this->tests as $name => $test)
149 : {
150 2 : $testsRun++;
151 : if ($verbose)
152 2 : {
153 1 : Printer::info($testsRun . '/' . $testCount . ' - Runnig of the test "' . $test->getName() . '"');
154 1 : }
155 2 : $report = $this->testRunner->run($test, $verbose);
156 2 : $this->reportsPrinter->addReport($report);
157 2 : }
158 :
159 2 : $reportFilePath = $this->reportsPrinter->printAll();
160 :
161 2 : return $reportFilePath;
162 : }
163 :
164 :
165 : }
|