Completed
Push — focus-safety ( 95178f )
by Erin
05:06
created

Runner::run()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
nc 2
nop 1
dl 0
loc 22
rs 8.9197
c 4
b 0
f 0
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
        $result->setIsFocusedByDsl($this->suite->isFocused());
49
        $focusPattern = $this->configuration->getFocusPattern();
50
        $skipPattern = $this->configuration->getSkipPattern();
51
52
        if ($focusPattern !== null || $skipPattern !== null) {
53
            $this->suite->applyFocusPatterns($focusPattern, $skipPattern);
54
        }
55
56
        $this->eventEmitter->on('test.failed', function () {
57
            if ($this->configuration->shouldStopOnFailure()) {
58
                $this->eventEmitter->emit('suite.halt');
59
            }
60
        });
61
62
        $this->eventEmitter->emit('runner.start');
63
        $this->suite->setEventEmitter($this->eventEmitter);
64
        $start = microtime(true);
65
        $this->suite->run($result);
66
        $this->eventEmitter->emit('runner.end', [microtime(true) - $start, $result]);
67
    }
68
}
69