From 53362991a82d5c1f3fa9fc21fe2263599f8d8692 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Mon, 31 May 2021 12:47:40 +0200 Subject: [PATCH] Additional unit tests to confirm behaviour when formulae reference cells within a merge range --- .../Calculation/MergedCellTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php diff --git a/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php b/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php new file mode 100644 index 00000000..a84cd26a --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/MergedCellTest.php @@ -0,0 +1,51 @@ +spreadSheet = new Spreadsheet(); + + $dataSheet = $this->spreadSheet->getActiveSheet(); + $dataSheet->setCellValue('A1', 1.1); + $dataSheet->setCellValue('A2', 2.2); + $dataSheet->mergeCells('A2:A4'); + $dataSheet->setCellValue('A5', 3.3); + } + + /** + * @dataProvider providerWorksheetFormulae + */ + public function testMergedCellBehaviour(string $formula, $expectedResult): void + { + $worksheet = $this->spreadSheet->getActiveSheet(); + + $worksheet->setCellValue('A7', $formula); + + $result = $worksheet->getCell('A7')->getCalculatedValue(); + self::assertSame($expectedResult, $result); + } + + public function providerWorksheetFormulae() + { + return [ + ['=SUM(A1:A5)', 6.6], + ['=COUNT(A1:A5)', 3], + ['=COUNTA(A1:A5)', 3], + ['=SUM(A3:A4)', 0], + ['=A2+A3+A4', 2.2], + ['=A2/A3', Functions::DIV0()], + ]; + } +}