mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 12:40:00 +00:00
e637713de9
When the Dynamic Array PR #3962 was introduced, it left the default as Return Array as Value. At some point, the default should be changed to Return Array as Array. This would, of course, be a breaking change, one which will not be part of Release 4. However, it will possibly be part of Release 5. Rather than relying on the default setting, this PR explicitly sets Return Array as Value when tests require that setting. This will make it easier to identify potential breaks when the default is changed. The entire test suite will now succeed with either setting as default. In making these changes, a few minor problems were discovered with how Array as Array is handled. These are fixed with this PR.
95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AllSetupTeardown extends TestCase
|
|
{
|
|
private string $compatibilityMode;
|
|
|
|
protected ?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 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 setCell(string $cell, mixed $value): void
|
|
{
|
|
if ($value !== null) {
|
|
if (is_string($value) && is_numeric($value)) {
|
|
$this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
|
|
} else {
|
|
$this->getSheet()->getCell($cell)->setValue($value);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
protected function setArrayAsValue(): void
|
|
{
|
|
$spreadsheet = $this->getSpreadsheet();
|
|
$calculation = Calculation::getInstance($spreadsheet);
|
|
$calculation->setInstanceArrayReturnType(
|
|
Calculation::RETURN_ARRAY_AS_VALUE
|
|
);
|
|
}
|
|
}
|