Completed
Push — master ( 11aa12...25ec1c )
by Erin
01:41
created

Runner::applyFocus()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 9.4285
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