Skip to content

Commit 5336299

Browse files
MarkBakerMarkBaker
authored andcommitted
Additional unit tests to confirm behaviour when formulae reference cells within a merge range
1 parent 59aae87 commit 5336299

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
4+
5+
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
7+
use PHPStan\Testing\TestCase;
8+
9+
class MergedCellTest extends TestCase
10+
{
11+
/**
12+
* @var Spreadsheet
13+
*/
14+
protected $spreadSheet;
15+
16+
protected function setUp(): void
17+
{
18+
$this->spreadSheet = new Spreadsheet();
19+
20+
$dataSheet = $this->spreadSheet->getActiveSheet();
21+
$dataSheet->setCellValue('A1', 1.1);
22+
$dataSheet->setCellValue('A2', 2.2);
23+
$dataSheet->mergeCells('A2:A4');
24+
$dataSheet->setCellValue('A5', 3.3);
25+
}
26+
27+
/**
28+
* @dataProvider providerWorksheetFormulae
29+
*/
30+
public function testMergedCellBehaviour(string $formula, $expectedResult): void
31+
{
32+
$worksheet = $this->spreadSheet->getActiveSheet();
33+
34+
$worksheet->setCellValue('A7', $formula);
35+
36+
$result = $worksheet->getCell('A7')->getCalculatedValue();
37+
self::assertSame($expectedResult, $result);
38+
}
39+
40+
public function providerWorksheetFormulae()
41+
{
42+
return [
43+
['=SUM(A1:A5)', 6.6],
44+
['=COUNT(A1:A5)', 3],
45+
['=COUNTA(A1:A5)', 3],
46+
['=SUM(A3:A4)', 0],
47+
['=A2+A3+A4', 2.2],
48+
['=A2/A3', Functions::DIV0()],
49+
];
50+
}
51+
}

0 commit comments

Comments
 (0)