Failed Conditions
Pull Request — master (#3876)
by Abdul Malik
22:45 queued 13:31
created

ReferenceHelper2Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 31
c 1
b 0
f 0
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testNoClone() 0 6 1
A testRenamedWorksheetInFormula() 0 28 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests;
6
7
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
8
use PhpOffice\PhpSpreadsheet\ReferenceHelper;
0 ignored issues
show
Bug introduced by
The type PhpOffice\PhpSpreadsheet\ReferenceHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use PhpOffice\PhpSpreadsheet\Spreadsheet;
10
use PHPUnit\Framework\TestCase;
11
12
class ReferenceHelper2Test extends TestCase
13
{
14
    public function testNoClone(): void
15
    {
16
        $this->expectException(SpreadsheetException::class);
17
        $this->expectExceptionMessage('Cloning a Singleton');
18
        $referenceHelper = ReferenceHelper::getInstance();
19
        clone $referenceHelper;
20
    }
21
22
    public function testRenamedWorksheetInFormula(): void
23
    {
24
        $spreadsheet = new Spreadsheet();
25
        $sheet1 = $spreadsheet->getActiveSheet();
26
        $referenceHelper = ReferenceHelper::getInstance();
27
        $referenceHelper->updateNamedFormulae($spreadsheet); // no-op
28
        $sheet2 = $spreadsheet->createSheet();
29
        $sheet2->setTitle('Sheet2');
30
        $title2 = $sheet2->getTitle();
31
        $sheet2->getCell('A1')->setValue(10);
32
        $sheet2->getCell('A2')->setValue(20);
33
        $sheet3 = $spreadsheet->createSheet();
34
        $sheet3->setTitle('Sheet3');
35
        $title3 = $sheet3->getTitle();
36
        $sheet3->getCell('A1')->setValue(30);
37
        $sheet3->getCell('A2')->setValue(40);
38
        $sheet1->getCell('A1')->setValue("=$title2!A1");
39
        $sheet1->getCell('A2')->setValue("='$title2'!A2");
40
        $sheet1->getCell('B1')->setValue("=$title3!A1");
41
        $sheet1->getCell('B2')->setValue("='$title3'!A2");
42
        $newTitle2 = 'renamedSheet2';
43
        $sheet2->setTitle($newTitle2);
44
        self::assertSame("=$newTitle2!A1", $sheet1->getCell('A1')->getValue());
45
        self::assertSame("='$newTitle2'!A2", $sheet1->getCell('A2')->getValue());
46
        self::assertSame("=$title3!A1", $sheet1->getCell('B1')->getValue());
47
        self::assertSame("='$title3'!A2", $sheet1->getCell('B2')->getValue());
48
        self::assertSame([[10, 30], [20, 40]], $sheet1->toArray(null, true, false));
49
        $spreadsheet->disconnectWorksheets();
50
    }
51
}
52