From fdd9f8c93984a136d9c03bd6bf29cdcaae6ba73e Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Sat, 24 Aug 2024 17:40:23 -0700 Subject: [PATCH] Better Definitions for Mixed Parameters and Values Part 4 of Many Continuing work started with PR #4016, PR #4026, and PR #4060. Improve documentation within program by making explicit what types of values are allowed for variables described as "mixed". In order to avoid broken functionality, this is done mainly through doc-blocks. This will get us closer to Phpstan Level 9, but many changes will be needed before we can consider that. After this PR, all the remaining changes will be in src/Calculation. --- src/PhpSpreadsheet/Cell/Cell.php | 4 +- src/PhpSpreadsheet/Reader/Xlsx.php | 100 +++++++++++------- .../Functions/MathTrig/TruncTest.php | 4 +- .../Functions/TextData/ConcatenateTest.php | 1 + .../Reader/Gnumeric/ArrayFormula2Test.php | 2 +- .../Reader/Gnumeric/ArrayFormulaTest.php | 2 +- .../Reader/Ods/ArrayFormulaTest.php | 2 +- .../Reader/Xml/ArrayFormulaTest.php | 2 +- .../Writer/Xlsx/ArrayFunctions2Test.php | 4 +- 9 files changed, 75 insertions(+), 46 deletions(-) diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index c976d4df9e..646d738227 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -191,7 +191,7 @@ public function getFormattedValue(): string $currentCalendar = SharedDate::getExcelCalendar(); SharedDate::setExcelCalendar($this->getWorksheet()->getParent()?->getExcelCalendar()); $formattedValue = (string) NumberFormat::toFormattedString( - $this->getCalculatedValue(), + $this->getCalculatedValueString(), (string) $this->getStyle()->getNumberFormat()->getFormatCode(true) ); SharedDate::setExcelCalendar($currentCalendar); @@ -920,7 +920,7 @@ public function setXfIndex(int $indexValue): self * * @return $this */ - public function setFormulaAttributes(mixed $attributes): self + public function setFormulaAttributes(null|array $attributes): self { $this->formulaAttributes = $attributes; diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index bcf2459739..ae55df27aa 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -41,6 +41,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use SimpleXMLElement; +use Stringable; use Throwable; use XMLReader; use ZipArchive; @@ -240,7 +241,7 @@ public function listWorksheetInfo(string $filename): array 'totalColumns' => 0, ]; - $fileWorksheet = (string) $worksheets[(string) self::getArrayItem(self::getAttributes($eleSheet, $namespace), 'id')]; + $fileWorksheet = (string) $worksheets[self::getArrayItemString(self::getAttributes($eleSheet, $namespace), 'id')]; $fileWorksheetPath = str_starts_with($fileWorksheet, '/') ? substr($fileWorksheet, 1) : "$dir/$fileWorksheet"; $xml = new XMLReader(); @@ -569,6 +570,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $relType = "rel:Relationship[@Type='" . "$xmlNamespaceBase/styles" . "']"; + /** @var ?SimpleXMLElement */ $xpath = self::getArrayItem(self::xpathNoFalse($relsWorkbook, $relType)); if ($xpath === null) { @@ -604,6 +606,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet if ($xf['numFmtId']) { if (isset($numFmts)) { + /** @var ?SimpleXMLElement */ $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); if (isset($tmpNumFmt['formatCode'])) { @@ -649,6 +652,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $xf = self::getAttributes($xfTag); $numFmt = NumberFormat::FORMAT_GENERAL; if ($numFmts && $xf['numFmtId']) { + /** @var ?SimpleXMLElement */ $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); if (isset($tmpNumFmt['formatCode'])) { $numFmt = (string) $tmpNumFmt['formatCode']; @@ -692,6 +696,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet //. Namespaces::SHARED_STRINGS . "$xmlNamespaceBase/sharedStrings" . "']"; + /** @var ?SimpleXMLElement */ $xpath = self::getArrayItem($relsWorkbook->xpath($relType)); if ($xpath) { @@ -751,7 +756,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet continue; } - $sheetReferenceId = (string) self::getArrayItem(self::getAttributes($eleSheet, $xmlNamespaceBase), 'id'); + $sheetReferenceId = self::getArrayItemString(self::getAttributes($eleSheet, $xmlNamespaceBase), 'id'); if (isset($worksheets[$sheetReferenceId]) === false) { ++$countSkippedSheets; $mapSheetId[$oldSheetId] = null; @@ -869,9 +874,16 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet } else { // Formula $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, 'castToBoolean'); - if (isset($c->f['t'])) { - $att = $c->f; - $docSheet->getCell($r)->setFormulaAttributes($att); + $formulaAttributes = []; + $attributes = $c->f->attributes(); + if (isset($attributes['t'])) { + $formulaAttributes['t'] = (string) $attributes['t']; + } + if (isset($attributes['ref'])) { + $formulaAttributes['ref'] = (string) $attributes['ref']; + } + if (!empty($formulaAttributes)) { + $docSheet->getCell($r)->setFormulaAttributes($formulaAttributes); } } @@ -1374,7 +1386,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $unparsedDrawings = []; $fileDrawing = null; foreach ($xmlSheetNS->drawing as $drawing) { - $drawingRelId = (string) self::getArrayItem(self::getAttributes($drawing, $xmlNamespaceBase), 'id'); + $drawingRelId = self::getArrayItemString(self::getAttributes($drawing, $xmlNamespaceBase), 'id'); $fileDrawing = $drawings[$drawingRelId]; $drawingFilename = dirname($fileDrawing) . '/_rels/' . basename($fileDrawing) . '.rels'; $relsDrawing = $this->loadZip($drawingFilename, Namespaces::RELATIONSHIPS); @@ -1428,9 +1440,9 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $outerShdw = $oneCellAnchor->pic->spPr->children(Namespaces::DRAWINGML)->effectLst->outerShdw; $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); - $objDrawing->setName((string) self::getArrayItem(self::getAttributes($oneCellAnchor->pic->nvPicPr->cNvPr), 'name')); - $objDrawing->setDescription((string) self::getArrayItem(self::getAttributes($oneCellAnchor->pic->nvPicPr->cNvPr), 'descr')); - $embedImageKey = (string) self::getArrayItem( + $objDrawing->setName(self::getArrayItemString(self::getAttributes($oneCellAnchor->pic->nvPicPr->cNvPr), 'name')); + $objDrawing->setDescription(self::getArrayItemString(self::getAttributes($oneCellAnchor->pic->nvPicPr->cNvPr), 'descr')); + $embedImageKey = self::getArrayItemString( self::getAttributes($blip, $xmlNamespaceBase), 'embed' ); @@ -1441,7 +1453,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet false ); } else { - $linkImageKey = (string) self::getArrayItem( + $linkImageKey = self::getArrayItemString( $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'link' ); @@ -1455,22 +1467,22 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $objDrawing->setOffsetX((int) Drawing::EMUToPixels($oneCellAnchor->from->colOff)); $objDrawing->setOffsetY(Drawing::EMUToPixels($oneCellAnchor->from->rowOff)); $objDrawing->setResizeProportional(false); - $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($oneCellAnchor->ext), 'cx'))); - $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($oneCellAnchor->ext), 'cy'))); + $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($oneCellAnchor->ext), 'cx'))); + $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($oneCellAnchor->ext), 'cy'))); if ($xfrm) { - $objDrawing->setRotation((int) Drawing::angleToDegrees(self::getArrayItem(self::getAttributes($xfrm), 'rot'))); + $objDrawing->setRotation((int) Drawing::angleToDegrees(self::getArrayItemIntOrSxml(self::getAttributes($xfrm), 'rot'))); $objDrawing->setFlipVertical((bool) self::getArrayItem(self::getAttributes($xfrm), 'flipV')); $objDrawing->setFlipHorizontal((bool) self::getArrayItem(self::getAttributes($xfrm), 'flipH')); } if ($outerShdw) { $shadow = $objDrawing->getShadow(); $shadow->setVisible(true); - $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($outerShdw), 'blurRad'))); - $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($outerShdw), 'dist'))); - $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem(self::getAttributes($outerShdw), 'dir'))); - $shadow->setAlignment((string) self::getArrayItem(self::getAttributes($outerShdw), 'algn')); + $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($outerShdw), 'blurRad'))); + $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($outerShdw), 'dist'))); + $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItemIntOrSxml(self::getAttributes($outerShdw), 'dir'))); + $shadow->setAlignment(self::getArrayItemString(self::getAttributes($outerShdw), 'algn')); $clr = $outerShdw->srgbClr ?? $outerShdw->prstClr; - $shadow->getColor()->setRGB(self::getArrayItem(self::getAttributes($clr), 'val')); + $shadow->getColor()->setRGB(self::getArrayItemString(self::getAttributes($clr), 'val')); $shadow->setAlpha(self::getArrayItem(self::getAttributes($clr->alpha), 'val') / 1000); } @@ -1482,8 +1494,8 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $coordinates = Coordinate::stringFromColumnIndex(((int) $oneCellAnchor->from->col) + 1) . ($oneCellAnchor->from->row + 1); $offsetX = Drawing::EMUToPixels($oneCellAnchor->from->colOff); $offsetY = Drawing::EMUToPixels($oneCellAnchor->from->rowOff); - $width = Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($oneCellAnchor->ext), 'cx')); - $height = Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($oneCellAnchor->ext), 'cy')); + $width = Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($oneCellAnchor->ext), 'cx')); + $height = Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($oneCellAnchor->ext), 'cy')); $graphic = $oneCellAnchor->graphicFrame->children(Namespaces::DRAWINGML)->graphic; /** @var SimpleXMLElement $chartRef */ @@ -1517,9 +1529,9 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet if (isset($editAs, $editAs['editAs'])) { $objDrawing->setEditAs($editAs['editAs']); } - $objDrawing->setName((string) self::getArrayItem(self::getAttributes($twoCellAnchor->pic->nvPicPr->cNvPr), 'name')); - $objDrawing->setDescription((string) self::getArrayItem(self::getAttributes($twoCellAnchor->pic->nvPicPr->cNvPr), 'descr')); - $embedImageKey = (string) self::getArrayItem( + $objDrawing->setName(self::getArrayItemString(self::getAttributes($twoCellAnchor->pic->nvPicPr->cNvPr), 'name')); + $objDrawing->setDescription(self::getArrayItemString(self::getAttributes($twoCellAnchor->pic->nvPicPr->cNvPr), 'descr')); + $embedImageKey = self::getArrayItemString( self::getAttributes($blip, $xmlNamespaceBase), 'embed' ); @@ -1530,7 +1542,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet false ); } else { - $linkImageKey = (string) self::getArrayItem( + $linkImageKey = self::getArrayItemString( $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'link' ); @@ -1552,21 +1564,21 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $objDrawing->setResizeProportional(false); if ($xfrm) { - $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($xfrm->ext), 'cx'))); - $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($xfrm->ext), 'cy'))); - $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem(self::getAttributes($xfrm), 'rot'))); + $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($xfrm->ext), 'cx'))); + $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($xfrm->ext), 'cy'))); + $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItemIntOrSxml(self::getAttributes($xfrm), 'rot'))); $objDrawing->setFlipVertical((bool) self::getArrayItem(self::getAttributes($xfrm), 'flipV')); $objDrawing->setFlipHorizontal((bool) self::getArrayItem(self::getAttributes($xfrm), 'flipH')); } if ($outerShdw) { $shadow = $objDrawing->getShadow(); $shadow->setVisible(true); - $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($outerShdw), 'blurRad'))); - $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem(self::getAttributes($outerShdw), 'dist'))); - $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem(self::getAttributes($outerShdw), 'dir'))); - $shadow->setAlignment((string) self::getArrayItem(self::getAttributes($outerShdw), 'algn')); + $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($outerShdw), 'blurRad'))); + $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItemIntOrSxml(self::getAttributes($outerShdw), 'dist'))); + $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItemIntOrSxml(self::getAttributes($outerShdw), 'dir'))); + $shadow->setAlignment(self::getArrayItemString(self::getAttributes($outerShdw), 'algn')); $clr = $outerShdw->srgbClr ?? $outerShdw->prstClr; - $shadow->getColor()->setRGB(self::getArrayItem(self::getAttributes($clr), 'val')); + $shadow->getColor()->setRGB(self::getArrayItemString(self::getAttributes($clr), 'val')); $shadow->setAlpha(self::getArrayItem(self::getAttributes($clr->alpha), 'val') / 1000); } @@ -1604,8 +1616,8 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet /** @var SimpleXMLElement $chartRef */ $chartRef = $graphic->graphicData->children(Namespaces::CHART)->chart; $thisChart = (string) self::getAttributes($chartRef, $xmlNamespaceBase); - $width = Drawing::EMUToPixels((int) self::getArrayItem(self::getAttributes($absoluteAnchor->ext), 'cx')[0]); - $height = Drawing::EMUToPixels((int) self::getArrayItem(self::getAttributes($absoluteAnchor->ext), 'cy')[0]); + $width = Drawing::EMUToPixels((int) self::getArrayItemString(self::getAttributes($absoluteAnchor->ext), 'cx')[0]); + $height = Drawing::EMUToPixels((int) self::getArrayItemString(self::getAttributes($absoluteAnchor->ext), 'cy')[0]); $chartDetails[$docSheet->getTitle() . '!' . $thisChart] = [ 'fromCoordinate' => 'A1', @@ -1638,7 +1650,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet } if ($xmlSheet->legacyDrawing && !$this->readDataOnly) { foreach ($xmlSheet->legacyDrawing as $drawing) { - $drawingRelId = (string) self::getArrayItem(self::getAttributes($drawing, $xmlNamespaceBase), 'id'); + $drawingRelId = self::getArrayItemString(self::getAttributes($drawing, $xmlNamespaceBase), 'id'); if (isset($vmlDrawingContents[$drawingRelId])) { $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['legacyDrawing'] = $vmlDrawingContents[$drawingRelId]; } @@ -2007,6 +2019,20 @@ private static function getArrayItem(null|array|bool|SimpleXMLElement $array, in return ($array === null || is_bool($array)) ? null : ($array[$key] ?? null); } + private static function getArrayItemString(null|array|bool|SimpleXMLElement $array, int|string $key = 0): string + { + $retVal = self::getArrayItem($array, $key); + + return ($retVal === null || is_scalar($retVal) || $retVal instanceof Stringable) ? ((string) $retVal) : ''; + } + + private static function getArrayItemIntOrSxml(null|array|bool|SimpleXMLElement $array, int|string $key = 0): int|SimpleXMLElement + { + $retVal = self::getArrayItem($array, $key); + + return (is_int($retVal) || $retVal instanceof SimpleXMLElement) ? $retVal : 0; + } + private static function dirAdd(null|SimpleXMLElement|string $base, null|SimpleXMLElement|string $add): string { $base = (string) $base; @@ -2071,7 +2097,7 @@ private function readHyperLinkDrawing(\PhpOffice\PhpSpreadsheet\Worksheet\Drawin $hlinkId = (string) self::getAttributes($hlinkClick, Namespaces::SCHEMA_OFFICE_DOCUMENT)['id']; $hyperlink = new Hyperlink( $hyperlinks[$hlinkId], - (string) self::getArrayItem(self::getAttributes($cellAnchor->pic->nvPicPr->cNvPr), 'name') + self::getArrayItemString(self::getAttributes($cellAnchor->pic->nvPicPr->cNvPr), 'name') ); $objDrawing->setHyperlink($hyperlink); } @@ -2237,7 +2263,7 @@ private function readBackgroundImage( string $relsName ): void { if ($xmlSheet && $xmlSheet->picture) { - $id = (string) self::getArrayItem(self::getAttributes($xmlSheet->picture, Namespaces::SCHEMA_OFFICE_DOCUMENT), 'id'); + $id = self::getArrayItemString(self::getAttributes($xmlSheet->picture, Namespaces::SCHEMA_OFFICE_DOCUMENT), 'id'); $rels = $this->loadZip($relsName); foreach ($rels->Relationship as $rel) { $attrs = $rel->attributes() ?? []; diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php index e82d7ccd9b..9e610f234f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php @@ -60,8 +60,8 @@ public function testTooMuchPrecision(mixed $expectedResult, float|int|string $va $sheet = $this->getSheet(); $sheet->getCell('E1')->setValue($value); $sheet->getCell('E2')->setValue("=TRUNC(E1,$digits)"); - $result = $sheet->getCell('E2')->getCalculatedValue(); - self::assertSame($expectedResult, (string) $result); + $result = $sheet->getCell('E2')->getCalculatedValueString(); + self::assertSame($expectedResult, $result); } public static function providerTooMuchPrecision(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php index be3cbd1ed6..3a5f33cff5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php @@ -30,6 +30,7 @@ public function testCONCATENATE(mixed $expectedResult, mixed ...$args): void $finalArg .= 'A3'; $sheet->getCell('A3')->setValue(str_repeat('Ԁ', DataType::MAX_STRING_LENGTH - 5)); } else { + self::assertTrue($arg === null || is_scalar($arg)); $finalArg .= '"' . (string) $arg . '"'; } } diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php index 58e1eebd6d..6ea143565f 100644 --- a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php +++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php @@ -26,7 +26,7 @@ public function testArrayFormulaReader( $cell = $worksheet->getCell($cellAddress); self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType()); self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes()); - self::assertSame($expectedFormula, strtoupper($cell->getValue())); + self::assertSame($expectedFormula, strtoupper($cell->getValueString())); Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $worksheet->calculateArrays(); $cell = $worksheet->getCell($cellAddress); diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php index 80817633a2..f0e9599cc7 100644 --- a/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php @@ -30,7 +30,7 @@ public function testArrayFormulaReader( } else { self::assertEmpty($cell->getFormulaAttributes()); } - self::assertSame($expectedFormula, strtoupper($cell->getValue())); + self::assertSame($expectedFormula, strtoupper($cell->getValueString())); Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $worksheet->calculateArrays(); $cell = $worksheet->getCell($cellAddress); diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php index 0c4cd1d453..726b42ba3f 100644 --- a/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php @@ -26,7 +26,7 @@ public function testArrayFormulaReader( $cell = $worksheet->getCell($cellAddress); self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType()); self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes()); - self::assertSame($expectedFormula, strtoupper($cell->getValue())); + self::assertSame($expectedFormula, strtoupper($cell->getValueString())); Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); $worksheet->calculateArrays(); $cell = $worksheet->getCell($cellAddress); diff --git a/tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php b/tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php index 6ba32aa334..9bc9621118 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php @@ -17,7 +17,7 @@ public function testArrayFormulaReader(): void self::assertSame(DataType::TYPE_FORMULA, $sheet->getCell('B1')->getDataType()); self::assertSame(['t' => 'array', 'ref' => 'B1:B3'], $sheet->getCell('B1')->getFormulaAttributes()); - self::assertSame('=CONCATENATE(A1:A3,"-",C1:C3)', strtoupper($sheet->getCell('B1')->getValue())); + self::assertSame('=CONCATENATE(A1:A3,"-",C1:C3)', strtoupper($sheet->getCell('B1')->getValueString())); self::assertSame('a-1', $sheet->getCell('B1')->getOldCalculatedValue()); self::assertSame('b-2', $sheet->getCell('B2')->getValue()); self::assertSame('c-3', $sheet->getCell('B3')->getValue()); diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php index ab3a54a4d3..c41a176fb8 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php @@ -268,7 +268,9 @@ public function testManyArraysOutput(): void { $json = file_get_contents('tests/data/Writer/XLSX/ArrayFunctions2.json'); self::assertNotFalse($json); - $this->trn = json_decode($json, true); + $trn = json_decode($json, true); + self::assertIsArray($trn); + $this->trn = $trn; $spreadsheet = new Spreadsheet(); Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);