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
|
|
|
|