Passed
Push — master ( e16571...85a9a3 )
by
unknown
23:21 queued 15:50
created

Issue1425Test   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setBackground() 0 9 1
A testIssue4125() 0 28 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
6
7
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8
use PhpOffice\PhpSpreadsheet\Style\Fill;
9
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
10
use PHPUnit\Framework\TestCase;
11
12
class Issue1425Test extends TestCase
13
{
14
    private static function setBackground(Worksheet $sheet, string $cells, string $color = 'ffffff00'): void
15
    {
16
        $sheet->getStyle($cells)
17
            ->getFill()
18
            ->setFillType(Fill::FILL_SOLID);
19
        $sheet->getStyle($cells)
20
            ->getFill()
21
            ->getStartColor()
22
            ->setArgb($color);
23
    }
24
25
    /**
26
     * Not extending styles to all cells after insertNewColumnBefore.
27
     */
28
    public function testIssue4125(): void
29
    {
30
        $spreadsheet = new Spreadsheet();
31
        $sheet = $spreadsheet->getActiveSheet();
32
        $sheet->setTitle('Before');
33
        $sheet->getCell('A1')->setValue(1);
34
        $sheet->getCell('A2')->setValue(2);
35
        $sheet->getCell('B1')->setValue(3);
36
        $sheet->getCell('B2')->setValue(4);
37
        self::setBackground($sheet, 'A1:A2');
38
        self::setBackground($sheet, 'B1:B2', 'FF00FFFF');
39
40
        $sheet->insertNewColumnBefore('B', 1);
41
42
        $expected = [
43
            'A1' => 'ffffff00',
44
            'A2' => 'ffffff00',
45
            'B1' => 'ffffff00',
46
            'B2' => 'ffffff00',
47
            'C1' => 'FF00FFFF',
48
            'C2' => 'FF00FFFF',
49
        ];
50
        foreach ($expected as $key => $value) {
51
            $color = $sheet->getStyle($key)
52
                ->getFill()->getStartColor()->getArgb();
53
            self::assertSame($value, $color, "error in cell $key");
54
        }
55
        $spreadsheet->disconnectWorksheets();
56
    }
57
}
58