1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\Date; |
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 int |
21
|
|
|
*/ |
22
|
|
|
private $excelCalendar; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $returnDateType; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ?Spreadsheet |
31
|
|
|
*/ |
32
|
|
|
private $spreadsheet; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ?Worksheet |
36
|
|
|
*/ |
37
|
|
|
private $sheet; |
38
|
|
|
|
39
|
|
|
protected function setUp(): void |
40
|
|
|
{ |
41
|
|
|
$this->compatibilityMode = Functions::getCompatibilityMode(); |
42
|
|
|
$this->excelCalendar = Date::getExcelCalendar(); |
43
|
|
|
$this->returnDateType = Functions::getReturnDateType(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function tearDown(): void |
47
|
|
|
{ |
48
|
|
|
Date::setExcelCalendar($this->excelCalendar); |
49
|
|
|
Functions::setCompatibilityMode($this->compatibilityMode); |
50
|
|
|
Functions::setReturnDateType($this->returnDateType); |
51
|
|
|
$this->sheet = null; |
52
|
|
|
if ($this->spreadsheet !== null) { |
53
|
|
|
$this->spreadsheet->disconnectWorksheets(); |
54
|
|
|
$this->spreadsheet = null; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected static function setMac1904(): void |
59
|
|
|
{ |
60
|
|
|
Date::setExcelCalendar(Date::CALENDAR_MAC_1904); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected static function setUnixReturn(): void |
64
|
|
|
{ |
65
|
|
|
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected static function setObjectReturn(): void |
69
|
|
|
{ |
70
|
|
|
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected static function setOpenOffice(): void |
74
|
|
|
{ |
75
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param mixed $expectedResult |
80
|
|
|
*/ |
81
|
|
|
protected function mightHaveException($expectedResult): void |
82
|
|
|
{ |
83
|
|
|
if ($expectedResult === 'exception') { |
84
|
|
|
$this->expectException(CalcException::class); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function getSpreadsheet(): Spreadsheet |
89
|
|
|
{ |
90
|
|
|
if ($this->spreadsheet !== null) { |
91
|
|
|
return $this->spreadsheet; |
92
|
|
|
} |
93
|
|
|
$this->spreadsheet = new Spreadsheet(); |
94
|
|
|
|
95
|
|
|
return $this->spreadsheet; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function getSheet(): Worksheet |
99
|
|
|
{ |
100
|
|
|
if ($this->sheet !== null) { |
101
|
|
|
return $this->sheet; |
102
|
|
|
} |
103
|
|
|
$this->sheet = $this->getSpreadsheet()->getActiveSheet(); |
104
|
|
|
|
105
|
|
|
return $this->sheet; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|