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()], + ]; + } +}