From b00dd47c28874ce086fe7875616a6ffe0a172d9d Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:19:51 -0700 Subject: [PATCH] Instance Variable for Array Return Type Till now we have used a static variable/getter/setter to decide what type of result should be returned when a formula is evaluated and an array is the result. This is messy; it would be much better to use an instance variable instead. We cannot eliminate `setArrayReturnType` and `getArrayReturnType` because that would be a BC break. I am considering whether they should be deprecated. In the meantime, I have added a new instance property `instanceArrayReturnType` with getter and setter methods. The property is initially null, and, if it remains so when needed, the static property will be used instead. However, if it is set, its value will be used. --- docs/topics/recipes.md | 9 +++- .../Calculation/Calculation.php | 50 ++++++++++++++++--- src/PhpSpreadsheet/Cell/Cell.php | 13 +++-- src/PhpSpreadsheet/Worksheet/Worksheet.php | 4 +- src/PhpSpreadsheet/Writer/Xlsx.php | 2 +- .../Calculation/ArrayTest.php | 38 ++++++++++++++ .../TextData/ConcatenateRangeTest.php | 16 +----- .../Functions/TextData/TextSplitTest.php | 16 +----- .../Calculation/InternalFunctionsTest.php | 16 +----- .../Cell/CellArrayFormulaTest.php | 22 ++------ .../Cell/CellFormulaTest.php | 14 +----- .../Functional/ArrayFunctionsCellTest.php | 15 +----- .../Functional/ArrayFunctionsSpillTest.php | 16 +----- .../Reader/Gnumeric/ArrayFormula2Test.php | 14 +----- .../Reader/Gnumeric/ArrayFormulaTest.php | 14 +----- .../Reader/Ods/ArrayFormulaTest.php | 14 +----- .../Reader/Ods/ArrayTest.php | 14 +----- .../Worksheet/Table/Issue3659Test.php | 15 +----- .../Writer/Csv/CsvArrayTest.php | 16 +----- .../Writer/Html/HtmlArrayTest.php | 16 +----- .../Writer/Ods/ArrayTest.php | 11 ++-- .../Writer/Xlsx/ArrayFunctions2Test.php | 10 +--- .../Writer/Xlsx/ArrayFunctionsInlineTest.php | 15 +----- .../Writer/Xlsx/ArrayFunctionsTest.php | 33 ++++-------- 24 files changed, 137 insertions(+), 266 deletions(-) diff --git a/docs/topics/recipes.md b/docs/topics/recipes.md index 5344d95a7..f07277c62 100644 --- a/docs/topics/recipes.md +++ b/docs/topics/recipes.md @@ -378,10 +378,17 @@ $value = $spreadsheet->getActiveSheet()->getCell('B8')->getCalculatedValue(); With version 2.0.3 of PhpSpreadsheet, we've introduced support for Excel "array formulas". **It is an opt-in feature.** You need to enable it with the following code: ```php +// preferred method +\PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance($spreadsheet) + ->setInstanceArrayReturnType( + \PhpOffice\PhpSpreadsheet\Calculation\Calculation::RETURN_ARRAY_AS_ARRAY); +// or less preferred \PhpOffice\PhpSpreadsheet\Calculation\Calculation::setArrayReturnType( \PhpOffice\PhpSpreadsheet\Calculation\Calculation::RETURN_ARRAY_AS_ARRAY); ``` -This is not a new function or constant, but it has till now not had much effect. +This is not a new constant, and setArrayReturnType is also not new, but it has till now not had much effect. +The instance variable set by the new setInstanceArrayReturnType +will always be checked first, and the static variable used only if the instance variable is uninitialized. As a basic example, let's look at a receipt for buying some fruit: diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index bbba6de5f..96d77e505 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -67,8 +67,12 @@ class Calculation const FORMULA_CLOSE_MATRIX_BRACE = '}'; const FORMULA_STRING_QUOTE = '"'; + /** Preferable to use instance variable instanceArrayReturnType rather than this static property. */ private static string $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE; + /** Preferable to use this instance variable rather than static returnArrayAsType */ + private ?string $instanceArrayReturnType = null; + /** * Instance of this class. * @@ -3003,6 +3007,38 @@ class Calculation return self::$returnArrayAsType; } + /** + * Set the Instance Array Return Type (Array or Value of first element in the array). + * + * @param string $returnType Array return type + * + * @return bool Success or failure + */ + public function setInstanceArrayReturnType(string $returnType): bool + { + if ( + ($returnType == self::RETURN_ARRAY_AS_VALUE) + || ($returnType == self::RETURN_ARRAY_AS_ERROR) + || ($returnType == self::RETURN_ARRAY_AS_ARRAY) + ) { + $this->instanceArrayReturnType = $returnType; + + return true; + } + + return false; + } + + /** + * Return the Array Return Type (Array or Value of first element in the array). + * + * @return string $returnType Array return type for instance if non-null, otherwise static property + */ + public function getInstanceArrayReturnType(): string + { + return $this->instanceArrayReturnType ?? self::$returnArrayAsType; + } + /** * Is calculation caching enabled? */ @@ -3506,9 +3542,9 @@ class Calculation throw new Exception($e->getMessage(), $e->getCode(), $e); } - if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) { + if (is_array($result) && self::getInstanceArrayReturnType() !== self::RETURN_ARRAY_AS_ARRAY) { $testResult = Functions::flattenArray($result); - if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) { + if (self::getInstanceArrayReturnType() == self::RETURN_ARRAY_AS_ERROR) { return ExcelError::VALUE(); } $result = array_shift($testResult); @@ -4556,9 +4592,7 @@ class Calculation // help us to know when pruning ['branchTestId' => true/false] $branchStore = []; // Loop through each token in turn - $tokenIdx = -1; - foreach ($tokens as $tokenData) { - ++$tokenIdx; + foreach ($tokens as $tokenIdx => $tokenData) { $this->processingAnchorArray = false; if ($tokenData['type'] === 'Cell Reference' && isset($tokens[$tokenIdx + 1]) && $tokens[$tokenIdx + 1]['type'] === 'Operand Count for Function ANCHORARRAY()') { $this->processingAnchorArray = true; @@ -4969,7 +5003,7 @@ class Calculation } } - if (self::$returnArrayAsType === self::RETURN_ARRAY_AS_ARRAY && !$this->processingAnchorArray && is_array($cellValue)) { + if (self::getInstanceArrayReturnType() === self::RETURN_ARRAY_AS_ARRAY && !$this->processingAnchorArray && is_array($cellValue)) { while (is_array($cellValue)) { $cellValue = array_shift($cellValue); } @@ -5433,7 +5467,7 @@ class Calculation sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow); if ($worksheet !== null && $worksheet->cellExists($aReferences[0])) { $temp = $worksheet->getCell($aReferences[0])->getCalculatedValue($resetLog); - if (self::$returnArrayAsType === self::RETURN_ARRAY_AS_ARRAY) { + if (self::getInstanceArrayReturnType() === self::RETURN_ARRAY_AS_ARRAY) { while (is_array($temp)) { $temp = array_shift($temp); } @@ -5449,7 +5483,7 @@ class Calculation sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow); if ($worksheet !== null && $worksheet->cellExists($reference)) { $temp = $worksheet->getCell($reference)->getCalculatedValue($resetLog); - if (self::$returnArrayAsType === self::RETURN_ARRAY_AS_ARRAY) { + if (self::getInstanceArrayReturnType() === self::RETURN_ARRAY_AS_ARRAY) { while (is_array($temp)) { $temp = array_shift($temp); } diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index 29649405a..40a82a9cd 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -404,17 +404,16 @@ class Cell implements Stringable try { $currentCalendar = SharedDate::getExcelCalendar(); SharedDate::setExcelCalendar($this->getWorksheet()->getParent()?->getExcelCalendar()); - $index = $this->getWorksheet()->getParentOrThrow()->getActiveSheetIndex(); - $selected = $this->getWorksheet()->getSelectedCells(); $thisworksheet = $this->getWorksheet(); + $index = $thisworksheet->getParentOrThrow()->getActiveSheetIndex(); + $selected = $thisworksheet->getSelectedCells(); $title = $thisworksheet->getTitle(); - $result = Calculation::getInstance( - $thisworksheet->getParent() - )->calculateCellValue($this, $resetLog); + $calculation = Calculation::getInstance($thisworksheet->getParent()); + $result = $calculation->calculateCellValue($this, $resetLog); $result = $this->convertDateTimeInt($result); $thisworksheet->setSelectedCells($selected); $thisworksheet->getParentOrThrow()->setActiveSheetIndex($index); - if (is_array($result) && Calculation::getArrayReturnType() !== Calculation::RETURN_ARRAY_AS_ARRAY) { + if (is_array($result) && $calculation->getInstanceArrayReturnType() !== Calculation::RETURN_ARRAY_AS_ARRAY) { while (is_array($result)) { $result = array_shift($result); } @@ -475,7 +474,7 @@ class Cell implements Stringable $thisworksheet->getCell($column . $row); } if (is_array($result)) { - if ($oldAttributes !== null && Calculation::getArrayReturnType() === Calculation::RETURN_ARRAY_AS_ARRAY) { + if ($oldAttributes !== null && $calculation->getInstanceArrayReturnType() === Calculation::RETURN_ARRAY_AS_ARRAY) { if (($oldAttributesT) === 'array') { $thisworksheet = $this->getWorksheet(); $coordinate = $this->getCoordinate(); diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index 85fb21552..1503c04b0 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -3686,7 +3686,7 @@ class Worksheet implements IComparable public function calculateArrays(bool $preCalculateFormulas = true): void { - if ($preCalculateFormulas && Calculation::getArrayReturnType() === Calculation::RETURN_ARRAY_AS_ARRAY) { + if ($preCalculateFormulas && Calculation::getInstance($this->parent)->getInstanceArrayReturnType() === Calculation::RETURN_ARRAY_AS_ARRAY) { $keys = $this->cellCollection->getCoordinates(); foreach ($keys as $key) { if ($this->getCell($key)->getDataType() === DataType::TYPE_FORMULA) { @@ -3698,7 +3698,7 @@ class Worksheet implements IComparable public function isCellInSpillRange(string $coordinate): bool { - if (Calculation::getArrayReturnType() !== Calculation::RETURN_ARRAY_AS_ARRAY) { + if (Calculation::getInstance($this->parent)->getInstanceArrayReturnType() !== Calculation::RETURN_ARRAY_AS_ARRAY) { return false; } $this->calculateArrays(); diff --git a/src/PhpSpreadsheet/Writer/Xlsx.php b/src/PhpSpreadsheet/Writer/Xlsx.php index 57ca689ad..edd0520bf 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx.php +++ b/src/PhpSpreadsheet/Writer/Xlsx.php @@ -737,6 +737,6 @@ class Xlsx extends BaseWriter private function determineUseDynamicArrays(): void { - $this->useDynamicArray = $this->preCalculateFormulas && Calculation::getInstance($this->spreadSheet)->getArrayReturnType() === Calculation::RETURN_ARRAY_AS_ARRAY && !$this->useCSEArrays; + $this->useDynamicArray = $this->preCalculateFormulas && Calculation::getInstance($this->spreadSheet)->getInstanceArrayReturnType() === Calculation::RETURN_ARRAY_AS_ARRAY && !$this->useCSEArrays; } } diff --git a/tests/PhpSpreadsheetTests/Calculation/ArrayTest.php b/tests/PhpSpreadsheetTests/Calculation/ArrayTest.php index 77b5251a7..2656de2ea 100644 --- a/tests/PhpSpreadsheetTests/Calculation/ArrayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/ArrayTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation; +use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; +use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class ArrayTest extends TestCase @@ -33,4 +35,40 @@ class ArrayTest extends TestCase self::assertIsNotArray($values[0]); self::assertIsNotArray($values[1]); } + + public function testPropagateStatic(): void + { + $oldValue = Calculation::getArrayReturnType(); + $calculation = new Calculation(); + self::assertTrue(Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY)); + self::assertFalse(Calculation::setArrayReturnType('xxx')); + self::assertSame(Calculation::RETURN_ARRAY_AS_ARRAY, Calculation::getArrayReturnType()); + self::assertFalse($calculation->setArrayReturnType('xxx')); + self::assertSame(Calculation::RETURN_ARRAY_AS_ARRAY, $calculation->getInstanceArrayReturnType()); + self::assertTrue($calculation->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ERROR)); + self::assertSame(Calculation::RETURN_ARRAY_AS_ARRAY, Calculation::getArrayReturnType()); + self::assertSame(Calculation::RETURN_ARRAY_AS_ERROR, $calculation->getInstanceArrayReturnType()); + Calculation::setArrayReturnType($oldValue); + } + + public function testReturnTypes(): void + { + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $calculation = Calculation::getInstance($spreadsheet); + $sheet->setCellValue('A1', 2.0); + $sheet->setCellValue('A2', 0.0); + $sheet->setCellValue('B1', 0.0); + $sheet->setCellValue('B2', 1.0); + $sheet->setCellValue('D1', '=MINVERSE(A1:B2)'); + $calculation->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ERROR); + self::assertSame('#VALUE!', $sheet->getCell('D1')->getCalculatedValue()); + $calculation->flushInstance(); + $calculation->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); + self::assertSame(0.5, $sheet->getCell('D1')->getCalculatedValue()); + $calculation->flushInstance(); + $calculation->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); + self::assertSame([[0.5, 0.0], [0.0, 1.0]], $sheet->getCell('D1')->getCalculatedValue()); + $spreadsheet->disconnectWorksheets(); + } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateRangeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateRangeTest.php index d4c618896..e90d55922 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateRangeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateRangeTest.php @@ -8,20 +8,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Calculation; class ConcatenateRangeTest extends AllSetupTeardown { - private string $arrayReturnType; - - protected function setUp(): void - { - parent::setUp(); - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - parent::tearDown(); - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testIssue4061(): void { $sheet = $this->getSheet(); @@ -37,7 +23,7 @@ class ConcatenateRangeTest extends AllSetupTeardown self::assertSame('a-1', $sheet->getCell('X1')->getCalculatedValue()); $sheet->getCell('D1')->setValue('=CONCAT(A1:A3, "-", C1:C3)'); self::assertSame('abc-123', $sheet->getCell('D1')->getCalculatedValue()); - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); + Calculation::getInstance($this->getSpreadsheet())->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet->getCell('E1')->setValue('=CONCATENATE(A1:A3, "-", C1:C3)'); self::assertSame([['a-1'], ['b-2'], ['c-3']], $sheet->getCell('E1')->getCalculatedValue()); $sheet->getCell('Y1')->setValue('=A1:A3&"-"&C1:C3'); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php index 5ccaa7c17..91f90fad8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php @@ -9,21 +9,6 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; class TextSplitTest extends AllSetupTeardown { - private string $returnType; - - protected function setUp(): void - { - parent::setUp(); - $this->returnType = Calculation::getInstance($this->getSpreadsheet())->getArrayReturnType(); - Calculation::getInstance($this->getSpreadsheet())->setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); - } - - protected function tearDown(): void - { - Calculation::getInstance($this->getSpreadsheet())->setArrayReturnType($this->returnType); - parent::tearDown(); - } - private function setDelimiterArgument(array $argument, string $column): string { return '{' . $column . implode(',' . $column, range(1, count($argument))) . '}'; @@ -46,6 +31,7 @@ class TextSplitTest extends AllSetupTeardown */ public function testTextSplit(array $expectedResult, array $arguments): void { + Calculation::getInstance($this->getSpreadsheet())->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $text = $arguments[0]; $columnDelimiter = $arguments[1]; $rowDelimiter = $arguments[2]; diff --git a/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php index d51d9a5fa..093922d13 100644 --- a/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php @@ -10,25 +10,13 @@ use PHPUnit\Framework\TestCase; class InternalFunctionsTest extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - /** * @dataProvider anchorArrayDataProvider */ public function testAnchorArrayFormula(string $reference, string $range, array $expectedResult): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet1 = $spreadsheet->getActiveSheet(); $sheet1->setTitle('SheetOne'); // no space in sheet title $sheet2 = $spreadsheet->createSheet(); @@ -68,8 +56,8 @@ class InternalFunctionsTest extends TestCase */ public function testSingleArrayFormula(string $reference, mixed $expectedResult): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet1 = $spreadsheet->getActiveSheet(); $sheet1->setTitle('SheetOne'); // no space in sheet title $sheet2 = $spreadsheet->createSheet(); diff --git a/tests/PhpSpreadsheetTests/Cell/CellArrayFormulaTest.php b/tests/PhpSpreadsheetTests/Cell/CellArrayFormulaTest.php index fd0d819bc..10b3b133f 100644 --- a/tests/PhpSpreadsheetTests/Cell/CellArrayFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Cell/CellArrayFormulaTest.php @@ -9,24 +9,12 @@ use PHPUnit\Framework\TestCase; class CellArrayFormulaTest extends TestCase { - private string $arrayReturnType; - private bool $skipUpdateInSpillageRange = true; - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testSetValueArrayFormulaNoSpillage(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $cell = $spreadsheet->getActiveSheet()->getCell('A1'); $cell->setValue('=MAX(ABS({5, -3; 1, -12}))'); @@ -37,8 +25,8 @@ class CellArrayFormulaTest extends TestCase public function testSetValueArrayFormulaWithSpillage(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $cell = $spreadsheet->getActiveSheet()->getCell('A1'); $cell->setValue('=SEQUENCE(3, 3, 1, 1)'); @@ -49,8 +37,8 @@ class CellArrayFormulaTest extends TestCase public function testSetValueInSpillageRangeCell(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $cell = $sheet->getCell('A1'); $cell->setValue('=SEQUENCE(3, 3, 1, 1)'); @@ -66,8 +54,8 @@ class CellArrayFormulaTest extends TestCase public function testUpdateValueInSpillageRangeCell(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=SEQUENCE(3, 3, 1, 1)'); $sheet->getCell('A1')->getCalculatedValue(); @@ -92,9 +80,9 @@ class CellArrayFormulaTest extends TestCase public function testUpdateArrayFormulaForSpillageRange(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); $calculation = Calculation::getInstance($spreadsheet); + $calculation->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=SEQUENCE(3, 3, 1, 1)'); $sheet->getCell('A1')->getCalculatedValue(); diff --git a/tests/PhpSpreadsheetTests/Cell/CellFormulaTest.php b/tests/PhpSpreadsheetTests/Cell/CellFormulaTest.php index 057d9fec9..1e588f4da 100644 --- a/tests/PhpSpreadsheetTests/Cell/CellFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Cell/CellFormulaTest.php @@ -10,18 +10,6 @@ use PHPUnit\Framework\TestCase; class CellFormulaTest extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testSetFormulaExplicit(): void { $formula = '=A2+B2'; @@ -96,10 +84,10 @@ class CellFormulaTest extends TestCase public function testSetArrayFormulaExplicitWithRange(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $formula = '=SEQUENCE(3,3,-10,2.5)'; $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $cell = $spreadsheet->getActiveSheet()->getCell('A1'); $cell->setValueExplicit($formula, DataType::TYPE_FORMULA); diff --git a/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsCellTest.php b/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsCellTest.php index 459c889c6..52873d0ab 100644 --- a/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsCellTest.php +++ b/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsCellTest.php @@ -10,23 +10,10 @@ use PHPUnit\Framework\TestCase; class ArrayFunctionsCellTest extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testArrayAndNonArrayOutput(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); - $calculation = Calculation::getInstance($spreadsheet); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->fromArray( diff --git a/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsSpillTest.php b/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsSpillTest.php index 6b46821d9..f2309071e 100644 --- a/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsSpillTest.php +++ b/tests/PhpSpreadsheetTests/Functional/ArrayFunctionsSpillTest.php @@ -11,23 +11,11 @@ use PHPUnit\Framework\TestCase; class ArrayFunctionsSpillTest extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testArrayOutput(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); $calculation = Calculation::getInstance($spreadsheet); + $calculation->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('B5', 'OCCUPIED'); @@ -119,8 +107,8 @@ class ArrayFunctionsSpillTest extends TestCase public function testSpillOperator(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->fromArray([ ['Product', 'Quantity', 'Price', 'Cost'], diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php index ec41c3558..58e1eebd6 100644 --- a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php +++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php @@ -9,18 +9,6 @@ use PHPUnit\Framework\TestCase; class ArrayFormula2Test extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - /** * @dataProvider arrayFormulaReaderProvider */ @@ -39,7 +27,7 @@ class ArrayFormula2Test extends TestCase self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType()); self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes()); self::assertSame($expectedFormula, strtoupper($cell->getValue())); - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $worksheet->calculateArrays(); $cell = $worksheet->getCell($cellAddress); self::assertSame($expectedValue, $cell->getCalculatedValue()); diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php index 861a2e05e..80817633a 100644 --- a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php @@ -9,18 +9,6 @@ use PHPUnit\Framework\TestCase; class ArrayFormulaTest extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - /** * @dataProvider arrayFormulaReaderProvider */ @@ -43,7 +31,7 @@ class ArrayFormulaTest extends TestCase self::assertEmpty($cell->getFormulaAttributes()); } self::assertSame($expectedFormula, strtoupper($cell->getValue())); - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $worksheet->calculateArrays(); $cell = $worksheet->getCell($cellAddress); self::assertSame($expectedValue, $cell->getCalculatedValue()); diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php index 2b37d3314..0c4cd1d45 100644 --- a/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php @@ -9,18 +9,6 @@ use PHPUnit\Framework\TestCase; class ArrayFormulaTest extends TestCase { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - /** * @dataProvider arrayFormulaReaderProvider */ @@ -39,7 +27,7 @@ class ArrayFormulaTest extends TestCase self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType()); self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes()); self::assertSame($expectedFormula, strtoupper($cell->getValue())); - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $worksheet->calculateArrays(); $cell = $worksheet->getCell($cellAddress); self::assertSame($expectedValue, $cell->getCalculatedValue()); diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/ArrayTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/ArrayTest.php index 1d53845b4..f594144a8 100644 --- a/tests/PhpSpreadsheetTests/Reader/Ods/ArrayTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Ods/ArrayTest.php @@ -10,22 +10,10 @@ use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class ArrayTest extends AbstractFunctional { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testSaveAndLoadHyperlinks(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheetOld = new Spreadsheet(); + Calculation::getInstance($spreadsheetOld)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheetOld->getActiveSheet(); $sheet->getCell('A1')->setValue('a'); $sheet->getCell('A2')->setValue('b'); diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/Issue3659Test.php b/tests/PhpSpreadsheetTests/Worksheet/Table/Issue3659Test.php index ff1108fe8..515db70d0 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/Issue3659Test.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/Issue3659Test.php @@ -9,19 +9,6 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Table; class Issue3659Test extends SetupTeardown { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - parent::tearDown(); - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testTableOnOtherSheet(): void { $spreadsheet = $this->getSpreadsheet(); @@ -61,8 +48,8 @@ class Issue3659Test extends SetupTeardown public function testTableAsArray(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = $this->getSpreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $this->getSheet(); $sheet->setTitle('Feuil1'); $tableSheet = $spreadsheet->createSheet(); diff --git a/tests/PhpSpreadsheetTests/Writer/Csv/CsvArrayTest.php b/tests/PhpSpreadsheetTests/Writer/Csv/CsvArrayTest.php index 834b19397..eb35e80a9 100644 --- a/tests/PhpSpreadsheetTests/Writer/Csv/CsvArrayTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Csv/CsvArrayTest.php @@ -10,22 +10,10 @@ use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class CsvArrayTest extends AbstractFunctional { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testArray(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue(1); $sheet->getCell('A2')->setValue(1); @@ -45,8 +33,8 @@ class CsvArrayTest extends AbstractFunctional public function testInlineArrays(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=UNIQUE({1;1;2;1;3;2;4;4;4})'); $sheet->getCell('D1')->setValue('=UNIQUE({1,1,2,1,3,2,4,4,4},true)'); diff --git a/tests/PhpSpreadsheetTests/Writer/Html/HtmlArrayTest.php b/tests/PhpSpreadsheetTests/Writer/Html/HtmlArrayTest.php index 665db3bff..6e3644080 100644 --- a/tests/PhpSpreadsheetTests/Writer/Html/HtmlArrayTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Html/HtmlArrayTest.php @@ -10,22 +10,10 @@ use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class HtmlArrayTest extends AbstractFunctional { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testArray(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue(1); $sheet->getCell('A2')->setValue(1); @@ -45,8 +33,8 @@ class HtmlArrayTest extends AbstractFunctional public function testInlineArrays(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=UNIQUE({1;1;2;1;3;2;4;4;4})'); $sheet->getCell('D1')->setValue('=UNIQUE({1,1,2,1,3,2,4,4,4},true)'); diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/ArrayTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/ArrayTest.php index 281b1c865..86c46d174 100644 --- a/tests/PhpSpreadsheetTests/Writer/Ods/ArrayTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Ods/ArrayTest.php @@ -13,8 +13,6 @@ use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class ArrayTest extends AbstractFunctional { - private string $arrayReturnType; - private string $samplesPath = 'tests/data/Writer/Ods'; private string $compatibilityMode; @@ -27,20 +25,18 @@ class ArrayTest extends AbstractFunctional $this->compatibilityMode = Functions::getCompatibilityMode(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); - $this->arrayReturnType = Calculation::getArrayReturnType(); } protected function tearDown(): void { parent::tearDown(); Functions::setCompatibilityMode($this->compatibilityMode); - Calculation::setArrayReturnType($this->arrayReturnType); } public function testArrayXml(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue(1); $sheet->getCell('A2')->setValue(1); @@ -54,14 +50,15 @@ class ArrayTest extends AbstractFunctional public function testArray(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue(1); $sheet->getCell('A2')->setValue(1); $sheet->getCell('A3')->setValue(3); $sheet->getCell('B1')->setValue('=UNIQUE(A1:A3)'); $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Ods'); + Calculation::getInstance($reloadedSpreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getCell('A1')->getValue()); self::assertSame(1, $sheet->getCell('A2')->getValue()); @@ -86,8 +83,8 @@ class ArrayTest extends AbstractFunctional if ($this->skipInline) { self::markTestIncomplete('Ods Reader/Writer alter commas and semi-colons within formulas, interfering with inline arrays'); } - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=UNIQUE({1;1;2;1;3;2;4;4;4})'); $sheet->getCell('D1')->setValue('=UNIQUE({1,1,2,1,3,2,4,4,4},true)'); diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php index 3d9ed8803..ab3a54a4d 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php @@ -52,18 +52,10 @@ class ArrayFunctions2Test extends TestCase private array $trn; - private string $arrayReturnType; - private string $outputFile = ''; - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - protected function tearDown(): void { - Calculation::setArrayReturnType($this->arrayReturnType); if ($this->outputFile !== '') { unlink($this->outputFile); $this->outputFile = ''; @@ -274,11 +266,11 @@ class ArrayFunctions2Test extends TestCase public function testManyArraysOutput(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $json = file_get_contents('tests/data/Writer/XLSX/ArrayFunctions2.json'); self::assertNotFalse($json); $this->trn = json_decode($json, true); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $wsPartijen = $spreadsheet->getActiveSheet(); $wsPartijen->setTitle('Partijen'); diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsInlineTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsInlineTest.php index e0b37921a..74d6f6bbf 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsInlineTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsInlineTest.php @@ -10,28 +10,17 @@ use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class ArrayFunctionsInlineTest extends AbstractFunctional { - private string $arrayReturnType; - - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - } - public function testInlineArrays(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=UNIQUE({1;1;2;1;3;2;4;4;4})'); $sheet->getCell('D1')->setValue('=UNIQUE({1,1,2,1,3,2,4,4,4},true)'); $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); $spreadsheet->disconnectWorksheets(); $rsheet = $reloadedSpreadsheet->getActiveSheet(); + Calculation::getInstance($reloadedSpreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $expected = [ ['=UNIQUE({1;1;2;1;3;2;4;4;4})', null, null, '=UNIQUE({1,1,2,1,3,2,4,4,4},true)', 2, 3, 4], [2, null, null, null, null, null, null], diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsTest.php index 58a84826d..630993206 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctionsTest.php @@ -13,28 +13,12 @@ use PHPUnit\Framework\TestCase; class ArrayFunctionsTest extends TestCase { - private string $arrayReturnType; - private string $outputFile = ''; - protected function setUp(): void - { - $this->arrayReturnType = Calculation::getArrayReturnType(); - } - - protected function tearDown(): void - { - Calculation::setArrayReturnType($this->arrayReturnType); - if ($this->outputFile !== '') { - unlink($this->outputFile); - $this->outputFile = ''; - } - } - public function testArrayOutput(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $columnArray = [ [41], @@ -67,6 +51,7 @@ class ArrayFunctionsTest extends TestCase $reader = new XlsxReader(); $spreadsheet2 = $reader->load($this->outputFile); + Calculation::getInstance($spreadsheet2)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet2 = $spreadsheet2->getActiveSheet(); $expectedUnique = [ [41], @@ -148,8 +133,8 @@ class ArrayFunctionsTest extends TestCase public function testArrayOutputCSE(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $columnArray = [ [41], @@ -183,6 +168,7 @@ class ArrayFunctionsTest extends TestCase $reader = new XlsxReader(); $spreadsheet2 = $reader->load($this->outputFile); + Calculation::getInstance($spreadsheet2)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet2 = $spreadsheet2->getActiveSheet(); $expectedUnique = [ [41], @@ -304,8 +290,8 @@ class ArrayFunctionsTest extends TestCase public function testArrayMultipleColumns(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $columnArray = [ [100, 91], @@ -324,6 +310,7 @@ class ArrayFunctionsTest extends TestCase $reader = new XlsxReader(); $spreadsheet2 = $reader->load($this->outputFile); + Calculation::getInstance($spreadsheet2)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet2 = $spreadsheet2->getActiveSheet(); $expectedUnique = [ [100, 91], @@ -354,8 +341,8 @@ class ArrayFunctionsTest extends TestCase public function testMetadataWritten(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $writer = new XlsxWriter($spreadsheet); $writerMetadata = new XlsxWriter\Metadata($writer); self::assertNotEquals('', $writerMetadata->writeMetaData()); @@ -367,8 +354,8 @@ class ArrayFunctionsTest extends TestCase public function testSpill(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A3')->setValue('x'); $sheet->getCell('A1')->setValue('=UNIQUE({1;2;3})'); @@ -379,6 +366,7 @@ class ArrayFunctionsTest extends TestCase $reader = new XlsxReader(); $spreadsheet2 = $reader->load($this->outputFile); + Calculation::getInstance($spreadsheet2)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet2 = $spreadsheet2->getActiveSheet(); self::assertSame('#SPILL!', $sheet2->getCell('A1')->getOldCalculatedValue()); self::assertSame('=UNIQUE({1;2;3})', $sheet2->getCell('A1')->getValue()); @@ -389,8 +377,8 @@ class ArrayFunctionsTest extends TestCase public function testArrayStringOutput(): void { - Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $spreadsheet = new Spreadsheet(); + Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet = $spreadsheet->getActiveSheet(); $columnArray = [ ['item1'], @@ -413,6 +401,7 @@ class ArrayFunctionsTest extends TestCase $reader = new XlsxReader(); $spreadsheet2 = $reader->load($this->outputFile); + Calculation::getInstance($spreadsheet2)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $sheet2 = $spreadsheet2->getActiveSheet(); $expectedUnique = [ ['item1'],