Skip to content

Commit 9893926

Browse files
authored
Add Test For NULL=0 (#2607)
Fix #2523. This isn't actually a fix; the problem was reported and confirmed for 1.21, but had already been fixed in master (and remains fixed in 1.22). This PR just adds a unit test for the original problem.
1 parent 71927f5 commit 9893926

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
4+
5+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class NullEqualsZeroTest extends TestCase
9+
{
10+
public function testNullEqualsZero(): void
11+
{
12+
// Confirm that NULL<>0 returns false
13+
$spreadsheet = new Spreadsheet();
14+
$sheet = $spreadsheet->getActiveSheet();
15+
$sheet->fromArray([
16+
['Item', 'QTY', 'RATE', 'RATE', 'Total'],
17+
['Bricks', 1000, 'Each', 0.55, '=IF(B2<>0,B2*D2,"INCL.")'],
18+
['Cement', null, null, null, '=IF(B3<>0,B3*D3,"INCL.")'],
19+
['Labour', 10, 'Hour', 45.00, '=IF(B4<>0,B4*D4,"INCL.")'],
20+
]);
21+
$sheet->setCellValue('A6', 'Total');
22+
$sheet->setCellValue('E6', '=SUM(E1:E5)');
23+
self::assertEquals(550.00, $sheet->getCell('E2')->getCalculatedValue());
24+
self::assertSame('INCL.', $sheet->getCell('E3')->getCalculatedValue());
25+
self::assertEquals(450.00, $sheet->getCell('E4')->getCalculatedValue());
26+
self::assertEquals(1000.00, $sheet->getCell('E6')->getCalculatedValue());
27+
28+
$sheet->setCellValue('Z1', '=Z2=0');
29+
self::assertTrue($sheet->getCell('Z1')->getCalculatedValue());
30+
$spreadsheet->disconnectWorksheets();
31+
}
32+
}

0 commit comments

Comments
 (0)