Failed Conditions
Push — master ( f65b0a...9a193f )
by
unknown
30s queued 21s
created

AllSetupTeardown::mightHaveException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
6
7
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
8
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
9
use PhpOffice\PhpSpreadsheet\Spreadsheet;
10
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
11
use PHPUnit\Framework\TestCase;
12
13
class AllSetupTeardown extends TestCase
14
{
15
    private string $compatibilityMode;
16
17
    private ?Spreadsheet $spreadsheet = null;
18
19
    private ?Worksheet $sheet = null;
20
21
    protected function setUp(): void
22
    {
23
        $this->compatibilityMode = Functions::getCompatibilityMode();
24
    }
25
26
    protected function tearDown(): void
27
    {
28
        Functions::setCompatibilityMode($this->compatibilityMode);
29
        $this->sheet = null;
30
        if ($this->spreadsheet !== null) {
31
            $this->spreadsheet->disconnectWorksheets();
32
            $this->spreadsheet = null;
33
        }
34
    }
35
36
    protected static function setExcel(): void
37
    {
38
        Functions::setCompatibilityMode(
39
            Functions::COMPATIBILITY_EXCEL
40
        );
41
    }
42
43
    protected static function setOpenOffice(): void
44
    {
45
        Functions::setCompatibilityMode(
46
            Functions::COMPATIBILITY_OPENOFFICE
47
        );
48
    }
49
50
    protected static function setGnumeric(): void
51
    {
52
        Functions::setCompatibilityMode(
53
            Functions::COMPATIBILITY_GNUMERIC
54
        );
55
    }
56
57
    protected function mightHaveException(mixed $expectedResult): void
58
    {
59
        if ($expectedResult === 'exception') {
60
            $this->expectException(CalcException::class);
61
        }
62
    }
63
64
    protected function getSpreadsheet(): Spreadsheet
65
    {
66
        if ($this->spreadsheet !== null) {
67
            return $this->spreadsheet;
68
        }
69
        $this->spreadsheet = new Spreadsheet();
70
71
        return $this->spreadsheet;
72
    }
73
74
    protected function getSheet(): Worksheet
75
    {
76
        if ($this->sheet !== null) {
77
            return $this->sheet;
78
        }
79
        $this->sheet = $this->getSpreadsheet()->getActiveSheet();
80
81
        return $this->sheet;
82
    }
83
}
84