mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 17:19:50 +02:00
Added missing tests
This commit is contained in:
@@ -55,4 +55,14 @@ class Color extends AbstractColor implements ColorInterface
|
||||
$this->alpha()
|
||||
];
|
||||
}
|
||||
|
||||
public function toInt(): int
|
||||
{
|
||||
$r = $this->red();
|
||||
$g = $this->green();
|
||||
$b = $this->blue();
|
||||
$a = intval(round($this->alpha() * 255));
|
||||
|
||||
return intval(($a << 24) + ($r << 16) + ($g << 8) + $b);
|
||||
}
|
||||
}
|
||||
|
@@ -10,4 +10,5 @@ interface ColorInterface
|
||||
public function alpha(): float;
|
||||
public function toArray(): array;
|
||||
public function toHex(): string;
|
||||
public function toInt(): int;
|
||||
}
|
||||
|
@@ -99,4 +99,12 @@ class InputHandlerTest extends TestCase
|
||||
$this->assertEquals(51, $result->green());
|
||||
$this->assertEquals(51, $result->blue());
|
||||
}
|
||||
|
||||
public function testHandleTransparent(): void
|
||||
{
|
||||
$handler = new InputHandler();
|
||||
$input = 'transparent';
|
||||
$result = $handler->handle($input);
|
||||
$this->assertInstanceOf(Color::class, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -84,4 +84,25 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals('b53717', $color->toHex());
|
||||
$this->assertEquals('#b53717', $color->toHex('#'));
|
||||
}
|
||||
|
||||
public function testToInt(): void
|
||||
{
|
||||
$color = $this->getTestColor(255, 255, 255);
|
||||
$this->assertEquals($color->toInt(), 4294967295);
|
||||
|
||||
$color = $this->getTestColor(255, 255, 255, 1);
|
||||
$this->assertEquals($color->toInt(), 4294967295);
|
||||
|
||||
$color = $this->getTestColor(181, 55, 23, 0.2);
|
||||
$this->assertEquals($color->toInt(), 867514135);
|
||||
|
||||
$color = $this->getTestColor(255, 255, 255, 0.5);
|
||||
$this->assertEquals($color->toInt(), 2164260863);
|
||||
|
||||
$color = $this->getTestColor(181, 55, 23, 1);
|
||||
$this->assertEquals($color->toInt(), 4290066199);
|
||||
|
||||
$color = $this->getTestColor(0, 0, 0, 0);
|
||||
$this->assertEquals($color->toInt(), 0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user