File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
tests/PhpSpreadsheetTests/Calculation Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments