Completed
Pull Request — master (#177)
by Erin
02:08
created

Runner::handleErrors()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 7
nc 1
nop 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
        $this->eventEmitter->on('test.failed', function () {
49
            if ($this->configuration->shouldStopOnFailure()) {
50
                $this->eventEmitter->emit('suite.halt');
51
            }
52
        });
53
54
        $this->eventEmitter->emit('runner.start');
55
        $this->suite->setEventEmitter($this->eventEmitter);
56
        $start = microtime(true);
57
        $this->suite->run($result);
58
        $this->eventEmitter->emit('runner.end', [microtime(true) - $start]);
59
    }
60
}
61