Failed Conditions
Pull Request — master (#1694)
by Adrien
08:05
created

ColorTest::testNewColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Style;
4
5
use PhpOffice\PhpSpreadsheet\Style\Color;
6
use PHPUnit\Framework\TestCase;
7
8
class ColorTest extends TestCase
9
{
10
    public function testNewColor(): void
11
    {
12
        $color = new Color('FF123456');
13
        self::assertEquals('FF123456', $color->getARGB());
14
        self::assertEquals('123456', $color->getRGB());
15
    }
16
17
    public function testARGBSetter(): void
18
    {
19
        $color = new Color();
20
        $color->setARGB('80123456');
21
        self::assertEquals('80123456', $color->getARGB());
22
        self::assertEquals('123456', $color->getRGB());
23
    }
24
25
    public function testARGBSetterEmpty(): void
26
    {
27
        $color = new Color();
28
        $color->setARGB();
29
        self::assertEquals(Color::COLOR_BLACK, $color->getARGB());
30
    }
31
32
    public function testARGBSetterInvalid(): void
33
    {
34
        $color = new Color('80123456');
35
        $color->setARGB('INVALID COLOR');
36
        self::assertEquals('80123456', $color->getARGB());
37
    }
38
39
    public function testRGBSetter(): void
40
    {
41
        $color = new Color();
42
        $color->setRGB('123456');
43
        self::assertEquals('123456', $color->getRGB());
44
        self::assertEquals('FF123456', $color->getARGB());
45
    }
46
47
    public function testRGBSetterEmpty(): void
48
    {
49
        $color = new Color();
50
        $color->setRGB();
51
        self::assertEquals(Color::COLOR_BLACK, $color->getARGB());
52
    }
53
54
    public function testRGBSetterInvalid(): void
55
    {
56
        $color = new Color('80123456');
57
        $color->setRGB('INVALID COLOR');
58
        self::assertEquals('123456', $color->getRGB());
59
    }
60
61
    public function testARGBFromArray(): void
62
    {
63
        $color = new Color();
64
        $color->applyFromArray(['argb' => '80123456']);
65
        self::assertEquals('80123456', $color->getARGB());
66
        self::assertEquals('123456', $color->getRGB());
67
    }
68
69
    public function testRGBFromArray(): void
70
    {
71
        $color = new Color();
72
        $color->applyFromArray(['rgb' => '123456']);
73
        self::assertEquals('123456', $color->getRGB());
74
        self::assertEquals('FF123456', $color->getARGB());
75
    }
76
77
    /**
78
     * @dataProvider providerColorGetRed
79
     *
80
     * @param mixed $expectedResult
81
     * @param mixed $color
82
     */
83
    public function testGetRed($expectedResult, $color, ...$args): void
84
    {
85
        $result = Color::getRed($color, ...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $hex of PhpOffice\PhpSpreadsheet\Style\Color::getRed() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
        $result = Color::getRed($color, /** @scrutinizer ignore-type */ ...$args);
Loading history...
86
        self::assertEquals($expectedResult, $result);
87
    }
88
89
    public function providerColorGetRed(): array
90
    {
91
        return require 'tests/data/Style/Color/ColorGetRed.php';
92
    }
93
94
    /**
95
     * @dataProvider providerColorGetGreen
96
     *
97
     * @param mixed $expectedResult
98
     * @param mixed $color
99
     */
100
    public function testGetGreen($expectedResult, $color, ...$args): void
101
    {
102
        $result = Color::getGreen($color, ...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $hex of PhpOffice\PhpSpreadsheet\Style\Color::getGreen() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

102
        $result = Color::getGreen($color, /** @scrutinizer ignore-type */ ...$args);
Loading history...
103
        self::assertEquals($expectedResult, $result);
104
    }
105
106
    public function providerColorGetGreen(): array
107
    {
108
        return require 'tests/data/Style/Color/ColorGetGreen.php';
109
    }
110
111
    /**
112
     * @dataProvider providerColorGetBlue
113
     *
114
     * @param mixed $expectedResult
115
     * @param mixed $color
116
     */
117
    public function testGetBlue($expectedResult, $color, ...$args): void
118
    {
119
        $result = Color::getBlue($color, ...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $hex of PhpOffice\PhpSpreadsheet\Style\Color::getBlue() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

119
        $result = Color::getBlue($color, /** @scrutinizer ignore-type */ ...$args);
Loading history...
120
        self::assertEquals($expectedResult, $result);
121
    }
122
123
    public function providerColorGetBlue(): array
124
    {
125
        return require 'tests/data/Style/Color/ColorGetBlue.php';
126
    }
127
128
    /**
129
     * @dataProvider providerColorChangeBrightness
130
     *
131
     * @param mixed $expectedResult
132
     */
133
    public function testChangeBrightness($expectedResult, ...$args): void
134
    {
135
        $result = Color::changeBrightness(...$args);
136
        self::assertEquals($expectedResult, $result);
137
    }
138
139
    public function providerColorChangeBrightness(): array
140
    {
141
        return require 'tests/data/Style/Color/ColorChangeBrightness.php';
142
    }
143
144
    public function testDefaultColor(): void
145
    {
146
        $color = new Color();
147
        $color->setARGB('FFFF0000');
148
        self::assertEquals('FFFF0000', $color->getARGB());
149
        self::assertEquals('FF0000', $color->getRGB());
150
        $color->setARGB('');
151
        self::assertEquals(Color::COLOR_BLACK, $color->getARGB());
152
        self::assertEquals('000000', $color->getRGB());
153
        $color->setARGB('FFFF0000');
154
        self::assertEquals('FFFF0000', $color->getARGB());
155
        self::assertEquals('FF0000', $color->getRGB());
156
        $color->setRGB('');
157
        self::assertEquals(Color::COLOR_BLACK, $color->getARGB());
158
        self::assertEquals('000000', $color->getRGB());
159
    }
160
}
161