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