1
|
|
|
<?php |
2
|
|
|
namespace Peridot\Runner; |
3
|
|
|
|
4
|
|
|
use Evenement\EventEmitterInterface; |
5
|
|
|
use Peridot\Configuration; |
6
|
|
|
use Peridot\Core\HasEventEmitterTrait; |
7
|
|
|
use Peridot\Core\TestResult; |
8
|
|
|
use Peridot\Core\Suite; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The Runner is responsible for running a given Suite. |
12
|
|
|
* |
13
|
|
|
* @package Peridot\Runner |
14
|
|
|
*/ |
15
|
|
|
class Runner implements RunnerInterface |
16
|
|
|
{ |
17
|
|
|
use HasEventEmitterTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \Peridot\Core\Suite |
21
|
|
|
*/ |
22
|
|
|
protected $suite; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \Peridot\Configuration |
26
|
|
|
*/ |
27
|
|
|
protected $configuration; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Suite $suite |
31
|
|
|
* @param Configuration $configuration |
32
|
|
|
* @param EventEmitterInterface $eventEmitter |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Suite $suite, Configuration $configuration, EventEmitterInterface $eventEmitter) |
35
|
|
|
{ |
36
|
|
|
$this->suite = $suite; |
37
|
|
|
$this->configuration = $configuration; |
38
|
|
|
$this->eventEmitter = $eventEmitter; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
* |
44
|
|
|
* @param TestResult $result |
45
|
|
|
*/ |
46
|
|
|
public function run(TestResult $result) |
47
|
|
|
{ |
48
|
|
|
$this->applyFocus($result); |
49
|
|
|
|
50
|
|
|
$this->eventEmitter->on('test.failed', function () { |
51
|
|
|
if ($this->configuration->shouldStopOnFailure()) { |
52
|
|
|
$this->eventEmitter->emit('suite.halt'); |
53
|
|
|
} |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
$this->eventEmitter->emit('runner.start'); |
57
|
|
|
$this->suite->setEventEmitter($this->eventEmitter); |
58
|
|
|
$start = microtime(true); |
59
|
|
|
$this->suite->run($result); |
60
|
|
|
$this->eventEmitter->emit('runner.end', [microtime(true) - $start, $result]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function applyFocus(TestResult $result) |
64
|
|
|
{ |
65
|
|
|
$result->setIsFocusedByDsl($this->suite->isFocused()); |
66
|
|
|
$focusPattern = $this->configuration->getFocusPattern(); |
67
|
|
|
$skipPattern = $this->configuration->getSkipPattern(); |
68
|
|
|
|
69
|
|
|
if ($focusPattern !== null || $skipPattern !== null) { |
70
|
|
|
$this->suite->applyFocusPatterns($focusPattern, $skipPattern); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|