1
0
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:
Oliver Vogel
2021-12-02 17:45:01 +01:00
parent eb2b597429
commit 9b48b23523
4 changed files with 40 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -10,4 +10,5 @@ interface ColorInterface
public function alpha(): float;
public function toArray(): array;
public function toHex(): string;
public function toInt(): int;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}