TestState::tearDownOnce()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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