Completed
Push — master ( a79865...f1a019 )
by Adrien
09:59
created

FormulaErrTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 5 2
A testFormulaError() 0 24 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Writer\Xls;
4
5
use PhpOffice\PhpSpreadsheet\IOFactory;
6
use PhpOffice\PhpSpreadsheet\NamedRange;
7
use PhpOffice\PhpSpreadsheet\Shared\File;
8
use PHPUnit\Framework\TestCase;
9
10
class FormulaErrTest extends TestCase
11
{
12
    protected function tearDown(): void
13
    {
14
        $filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
15
        if (file_exists($filename)) {
16
            unlink($filename);
17
        }
18
    }
19
20
    public function testFormulaError()
21
    {
22
        $obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
23
        $sheet0 = $obj->setActiveSheetIndex(0);
24
        $sheet0->setCellValue('A1', 2);
25
        $obj->addNamedRange(new NamedRange('DEFNAM', $sheet0, 'A1'));
26
        $sheet0->setCellValue('B1', '=2*DEFNAM');
27
        $sheet0->setCellValue('C1', '=DEFNAM=2');
28
        $sheet0->setCellValue('D1', '=CONCAT("X",DEFNAM)');
29
        $writer = IOFactory::createWriter($obj, 'Xls');
30
        $filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');
31
        $writer->save($filename);
32
        $reader = IOFactory::createReader('Xls');
33
        $robj = $reader->load($filename);
34
        $sheet0 = $robj->setActiveSheetIndex(0);
35
        $a1 = $sheet0->getCell('A1')->getCalculatedValue();
36
        self::assertEquals(2, $a1);
37
        $b1 = $sheet0->getCell('B1')->getCalculatedValue();
38
        self::assertEquals(4, $b1);
39
        $c1 = $sheet0->getCell('C1')->getCalculatedValue();
40
        $tru = true;
41
        self::assertEquals($tru, $c1);
42
        $d1 = $sheet0->getCell('D1')->getCalculatedValue();
43
        self::assertEquals('X2', $d1);
44
    }
45
}
46