Passed
Push — master ( 9204d2...7aa83e )
by Mark
09:43
created

AllSetupTeardown   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 84
rs 10
c 1
b 0
f 0
wmc 15

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSpreadsheet() 0 8 2
A setCell() 0 7 4
A setGnumeric() 0 3 1
A setOpenOffice() 0 3 1
A getSheet() 0 8 2
A tearDown() 0 7 2
A mightHaveException() 0 4 2
A setUp() 0 3 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
6
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7
use PhpOffice\PhpSpreadsheet\Cell\DataType;
8
use PhpOffice\PhpSpreadsheet\Spreadsheet;
9
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
10
use PHPUnit\Framework\TestCase;
11
12
class AllSetupTeardown extends TestCase
13
{
14
    /**
15
     * @var string
16
     */
17
    private $compatibilityMode;
18
19
    /**
20
     * @var ?Spreadsheet
21
     */
22
    private $spreadsheet;
23
24
    /**
25
     * @var ?Worksheet
26
     */
27
    private $sheet;
28
29
    protected function setUp(): void
30
    {
31
        $this->compatibilityMode = Functions::getCompatibilityMode();
32
    }
33
34
    protected function tearDown(): void
35
    {
36
        Functions::setCompatibilityMode($this->compatibilityMode);
37
        $this->sheet = null;
38
        if ($this->spreadsheet !== null) {
39
            $this->spreadsheet->disconnectWorksheets();
40
            $this->spreadsheet = null;
41
        }
42
    }
43
44
    protected static function setOpenOffice(): void
45
    {
46
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
47
    }
48
49
    protected static function setGnumeric(): void
50
    {
51
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
52
    }
53
54
    /**
55
     * @param mixed $expectedResult
56
     */
57
    protected function mightHaveException($expectedResult): void
58
    {
59
        if ($expectedResult === 'exception') {
60
            $this->expectException(CalcException::class);
61
        }
62
    }
63
64
    /**
65
     * @param mixed $value
66
     */
67
    protected function setCell(string $cell, $value): void
68
    {
69
        if ($value !== null) {
70
            if (is_string($value) && is_numeric($value)) {
71
                $this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
72
            } else {
73
                $this->getSheet()->getCell($cell)->setValue($value);
74
            }
75
        }
76
    }
77
78
    protected function getSpreadsheet(): Spreadsheet
79
    {
80
        if ($this->spreadsheet !== null) {
81
            return $this->spreadsheet;
82
        }
83
        $this->spreadsheet = new Spreadsheet();
84
85
        return $this->spreadsheet;
86
    }
87
88
    protected function getSheet(): Worksheet
89
    {
90
        if ($this->sheet !== null) {
91
            return $this->sheet;
92
        }
93
        $this->sheet = $this->getSpreadsheet()->getActiveSheet();
94
95
        return $this->sheet;
96
    }
97
}
98