Completed
Push — 4 ( d2cbf5...ae5aa4 )
by Maxime
05:55 queued 05:46
created

TestKernel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A bootPHP() 0 6 1
A reset() 0 5 1
A getIncludeTests() 0 3 1
A bootErrorHandling() 0 4 1
A setIgnoredCIConfigs() 0 4 1
A getIgnoredCIConfigs() 0 3 1
1
<?php
2
3
namespace SilverStripe\Dev;
4
5
use SilverStripe\Core\CoreKernel;
6
7
/**
8
 * Kernel for running unit tests
9
 */
10
class TestKernel extends CoreKernel
11
{
12
13
    /** @var string[] $ciConfigs */
14
    private $ciConfigs = [];
15
16
17
    public function __construct($basePath)
18
    {
19
        $this->setEnvironment(self::DEV);
20
        parent::__construct($basePath);
21
    }
22
23
    /**
24
     * Reset kernel between tests.
25
     * Note: this avoids resetting services (See TestState for service specific reset)
26
     *
27
     * @return $this
28
     */
29
    public function reset()
30
    {
31
        $this->setEnvironment(self::DEV);
32
        $this->bootPHP();
33
        return $this;
34
    }
35
36
    protected function bootPHP()
37
    {
38
        parent::bootPHP();
39
40
        // Set default timezone consistently to avoid NZ-specific dependencies
41
        date_default_timezone_set('UTC');
42
    }
43
44
    protected function getIncludeTests()
45
    {
46
        return true;
47
    }
48
49
50
    /**
51
     * Set a list of CI configurations that should cause a module's test not to be added to a manifest
52
     * @param string[] $ciConfigs
53
     */
54
    public function setIgnoredCIConfigs(array $ciConfigs): self
55
    {
56
        $this->ciConfigs = $ciConfigs;
57
        return $this;
58
    }
59
60
    protected function getIgnoredCIConfigs(): array
61
    {
62
        return $this->ciConfigs;
63
    }
64
65
    protected function bootErrorHandling()
66
    {
67
        // Leave phpunit to capture errors
68
        restore_error_handler();
69
    }
70
}
71