TestState   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDownOnce() 0 2 1
A setUpOnce() 0 3 1
A setUp() 0 3 1
A tearDown() 0 2 1
A disableTopPageUpdate() 0 5 1
1
<?php
2
3
namespace DNADesign\Elemental\TopPage;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\Dev\State\TestState as BaseState;
7
8
class TestState implements BaseState
9
{
10
    public function setUp(SapphireTest $test): void
11
    {
12
        $this->disableTopPageUpdate();
13
    }
14
15
    public function tearDown(SapphireTest $test): void
16
    {
17
    }
18
19
    public function setUpOnce($class): void
20
    {
21
        $this->disableTopPageUpdate();
22
    }
23
24
    public function tearDownOnce($class): void
25
    {
26
    }
27
28
    /**
29
     * We need to disable top page updates as it doesn't work with fixture builder and transactions in unit tests
30
     * caused by an attempt to traverse unsaved relations which is normally fine
31
     * the lookup failure causes the whole transaction to fail which is the whole unit test
32
     * this has no impact on the functionality, though
33
     */
34
    private function disableTopPageUpdate(): void
35
    {
36
        /** @var DataExtension $extension */
37
        $extension = singleton(DataExtension::class);
38
        $extension->disableTopPageUpdate();
39
    }
40
}
41