|
| 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