mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 04:28:51 +00:00
79fca7601c
This came to light while cleaning up ComplexAssert. Many tests are calling `_calculateFormulaValue` rather than `calculateFormula`, and, as a result, have to be trimmed before asserting. This PR changes those calls, and does a bit more to simplify the tests. There are a lot of other non-Engineering tests which call `_calculateFormulaValue`, but none of those need to manipulate the result after the test. This PR changes only tests, no source code.
84 lines
2.0 KiB
PHP
84 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AllSetupTeardown extends TestCase
|
|
{
|
|
private string $compatibilityMode;
|
|
|
|
private ?Spreadsheet $spreadsheet = null;
|
|
|
|
private ?Worksheet $sheet = null;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
$this->sheet = null;
|
|
if ($this->spreadsheet !== null) {
|
|
$this->spreadsheet->disconnectWorksheets();
|
|
$this->spreadsheet = null;
|
|
}
|
|
}
|
|
|
|
protected static function setExcel(): void
|
|
{
|
|
Functions::setCompatibilityMode(
|
|
Functions::COMPATIBILITY_EXCEL
|
|
);
|
|
}
|
|
|
|
protected static function setOpenOffice(): void
|
|
{
|
|
Functions::setCompatibilityMode(
|
|
Functions::COMPATIBILITY_OPENOFFICE
|
|
);
|
|
}
|
|
|
|
protected static function setGnumeric(): void
|
|
{
|
|
Functions::setCompatibilityMode(
|
|
Functions::COMPATIBILITY_GNUMERIC
|
|
);
|
|
}
|
|
|
|
protected function mightHaveException(mixed $expectedResult): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcException::class);
|
|
}
|
|
}
|
|
|
|
protected function getSpreadsheet(): Spreadsheet
|
|
{
|
|
if ($this->spreadsheet !== null) {
|
|
return $this->spreadsheet;
|
|
}
|
|
$this->spreadsheet = new Spreadsheet();
|
|
|
|
return $this->spreadsheet;
|
|
}
|
|
|
|
protected function getSheet(): Worksheet
|
|
{
|
|
if ($this->sheet !== null) {
|
|
return $this->sheet;
|
|
}
|
|
$this->sheet = $this->getSpreadsheet()->getActiveSheet();
|
|
|
|
return $this->sheet;
|
|
}
|
|
}
|