Skip to content

Commit c99ca79

Browse files
committed
Fix 6 char hex color code #217
1 parent 166ef96 commit c99ca79

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/Helpers/ColorHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public static function getArrayFromColorString(string $color): array {
3636
if (str_starts_with($color, '#') && strlen($color) === 7) {
3737
return [
3838
hexdec(substr($color, 1, 2)),
39-
hexdec(substr($color, 2, 2)),
4039
hexdec(substr($color, 3, 2)),
40+
hexdec(substr($color, 5, 2)),
4141
];
4242
}
4343

tests/Helpers/ColorHelperTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Helpers;
4+
5+
use Picqer\Barcode\Exceptions\UnknownColorException;
6+
use Picqer\Barcode\Helpers\ColorHelper;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class ColorHelperTest extends TestCase
10+
{
11+
public function test_convert_color_black()
12+
{
13+
$result = ColorHelper::getArrayFromColorString('black');
14+
15+
$this->assertEquals([0, 0, 0], $result);
16+
}
17+
18+
public function test_convert_color_hex_345()
19+
{
20+
$result = ColorHelper::getArrayFromColorString('#345');
21+
22+
$this->assertEquals([51, 68, 85], $result);
23+
}
24+
25+
public function test_convert_color_hex_334455()
26+
{
27+
$result = ColorHelper::getArrayFromColorString('#334455');
28+
29+
$this->assertEquals([51, 68, 85], $result);
30+
}
31+
32+
public function test_convert_color_hex_632343()
33+
{
34+
$result = ColorHelper::getArrayFromColorString('#632343');
35+
36+
$this->assertEquals([99, 35, 67], $result);
37+
}
38+
39+
public function test_throws_exception_on_unknown_color()
40+
{
41+
$this->expectException(UnknownColorException::class);
42+
43+
ColorHelper::getArrayFromColorString('aubergine');
44+
}
45+
}

0 commit comments

Comments
 (0)