Completed
Push — master ( 4ad6bd...3873e4 )
by Ingo
11:53
created

SapphireTestState   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getStates() 0 4 1
A setStates() 0 5 1
A setUp() 0 6 2
A tearDown() 0 8 2
A setUpOnce() 0 6 2
A tearDownOnce() 0 8 2
1
<?php
2
3
namespace SilverStripe\Dev\State;
4
5
use SilverStripe\Core\Injector\Injectable;
6
use SilverStripe\Dev\Debug;
7
use SilverStripe\Dev\SapphireTest;
8
9
class SapphireTestState implements TestState
10
{
11
    use Injectable;
12
13
    /**
14
     * @var TestState[]
15
     */
16
    protected $states = [];
17
18
    /**
19
     * @return TestState[]
20
     */
21
    public function getStates()
22
    {
23
        return $this->states;
24
    }
25
26
    /**
27
     * @param TestState[] $states
28
     * @return $this
29
     */
30
    public function setStates(array $states)
31
    {
32
        $this->states = $states;
33
        return $this;
34
    }
35
36
    public function setUp(SapphireTest $test)
37
    {
38
        foreach ($this->states as $state) {
39
            $state->setUp($test);
40
        }
41
    }
42
43
    public function tearDown(SapphireTest $test)
44
    {
45
        // Tear down in reverse order
46
        /** @var TestState $state */
47
        foreach (array_reverse($this->states) as $state) {
48
            $state->tearDown($test);
49
        }
50
    }
51
52
    public function setUpOnce($class)
53
    {
54
        foreach ($this->states as $state) {
55
            $state->setUpOnce($class);
56
        }
57
    }
58
59
    /**
60
     * Called once on tear down
61
     *
62
     * @param string $class Class being torn down
63
     */
64
    public function tearDownOnce($class)
65
    {
66
        // Tear down in reverse order
67
        /** @var TestState $state */
68
        foreach (array_reverse($this->states) as $state) {
69
            $state->tearDownOnce($class);
70
        }
71
    }
72
}
73