mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 09:10:21 +02:00
Add tests
This commit is contained in:
@@ -4,5 +4,4 @@ namespace Intervention\Image\Colors\Rgb\Channels;
|
||||
|
||||
class Blue extends Red
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@@ -4,5 +4,4 @@ namespace Intervention\Image\Colors\Rgb\Channels;
|
||||
|
||||
class Green extends Red
|
||||
{
|
||||
//
|
||||
}
|
||||
|
@@ -33,6 +33,25 @@ class ChannelTest extends TestCase
|
||||
$channel = new Channel(normalized: 2);
|
||||
}
|
||||
|
||||
public function testConstructorFail(): void
|
||||
{
|
||||
$this->expectException(ColorException::class);
|
||||
new Channel(200);
|
||||
}
|
||||
|
||||
public function testToInt(): void
|
||||
{
|
||||
$channel = new Channel(10);
|
||||
$this->assertEquals(10, $channel->toInt());
|
||||
}
|
||||
|
||||
public function testToString(): void
|
||||
{
|
||||
$channel = new Channel(10);
|
||||
$this->assertEquals("10", $channel->toString());
|
||||
$this->assertEquals("10", (string) $channel);
|
||||
}
|
||||
|
||||
public function testValue(): void
|
||||
{
|
||||
$channel = new Channel(10);
|
||||
|
@@ -8,6 +8,7 @@ use Intervention\Image\Colors\Cmyk\Channels\Magenta;
|
||||
use Intervention\Image\Colors\Cmyk\Channels\Yellow;
|
||||
use Intervention\Image\Colors\Cmyk\Color as Color;
|
||||
use Intervention\Image\Colors\Cmyk\Colorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -22,6 +23,12 @@ class ColorTest extends TestCase
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$color = Color::create('cmyk(10, 20, 30, 40)');
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
}
|
||||
|
||||
public function testColorspace(): void
|
||||
{
|
||||
$color = new Color(0, 0, 0, 0);
|
||||
@@ -43,6 +50,13 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals(10, $channel->value());
|
||||
}
|
||||
|
||||
public function testChannelNotFound(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30, 30);
|
||||
$this->expectException(ColorException::class);
|
||||
$color->channel('none');
|
||||
}
|
||||
|
||||
public function testCyanMagentaYellowKey(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30, 40);
|
||||
@@ -62,6 +76,22 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals([10, 20, 30, 40], $color->toArray());
|
||||
}
|
||||
|
||||
public function testToHex(): void
|
||||
{
|
||||
$color = new Color(0, 73, 100, 0);
|
||||
$this->assertEquals('ff4400', $color->toHex());
|
||||
$this->assertEquals('#ff4400', $color->toHex('#'));
|
||||
}
|
||||
|
||||
public function testIsGreyscale(): void
|
||||
{
|
||||
$color = new Color(0, 73, 100, 0);
|
||||
$this->assertFalse($color->isGreyscale());
|
||||
|
||||
$color = new Color(0, 0, 0, 50);
|
||||
$this->assertTrue($color->isGreyscale());
|
||||
}
|
||||
|
||||
public function testNormalize(): void
|
||||
{
|
||||
$color = new Color(100, 50, 20, 0);
|
||||
|
@@ -33,6 +33,25 @@ class ChannelTest extends TestCase
|
||||
$channel = new Hue(normalized: 2);
|
||||
}
|
||||
|
||||
public function testConstructorFail(): void
|
||||
{
|
||||
$this->expectException(ColorException::class);
|
||||
new Hue(400);
|
||||
}
|
||||
|
||||
public function testToInt(): void
|
||||
{
|
||||
$channel = new Hue(10);
|
||||
$this->assertEquals(10, $channel->toInt());
|
||||
}
|
||||
|
||||
public function testToString(): void
|
||||
{
|
||||
$channel = new Hue(10);
|
||||
$this->assertEquals("10", $channel->toString());
|
||||
$this->assertEquals("10", (string) $channel);
|
||||
}
|
||||
|
||||
public function testValue(): void
|
||||
{
|
||||
$channel = new Hue(10);
|
||||
|
16
tests/Colors/Hsl/Channels/SaturationTest.php
Normal file
16
tests/Colors/Hsl/Channels/SaturationTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Colors\Hsl\Channels;
|
||||
|
||||
use Intervention\Image\Colors\Hsl\Channels\Saturation;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
class SaturationTest extends TestCase
|
||||
{
|
||||
public function testMinMax(): void
|
||||
{
|
||||
$saturation = new Saturation(0);
|
||||
$this->assertEquals(0, $saturation->min());
|
||||
$this->assertEquals(100, $saturation->max());
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ use Intervention\Image\Colors\Hsl\Channels\Luminance;
|
||||
use Intervention\Image\Colors\Hsl\Channels\Saturation;
|
||||
use Intervention\Image\Colors\Hsl\Color;
|
||||
use Intervention\Image\Colors\Hsl\Colorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,12 @@ class ColorTest extends TestCase
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$color = Color::create('hsl(10, 20, 30)');
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
}
|
||||
|
||||
public function testColorspace(): void
|
||||
{
|
||||
$color = new Color(0, 0, 0);
|
||||
@@ -41,6 +48,13 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals(10, $channel->value());
|
||||
}
|
||||
|
||||
public function testChannelNotFound(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30);
|
||||
$this->expectException(ColorException::class);
|
||||
$color->channel('none');
|
||||
}
|
||||
|
||||
public function testHueSaturationLuminanceKey(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30);
|
||||
@@ -58,6 +72,12 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals([10, 20, 30], $color->toArray());
|
||||
}
|
||||
|
||||
public function testToHex(): void
|
||||
{
|
||||
$color = new Color(16, 100, 50);
|
||||
$this->assertEquals('ff4400', $color->toHex());
|
||||
}
|
||||
|
||||
public function testNormalize(): void
|
||||
{
|
||||
$color = new Color(180, 50, 25);
|
||||
|
@@ -34,6 +34,25 @@ class ChannelTest extends TestCase
|
||||
$channel = new Hue(normalized: 2);
|
||||
}
|
||||
|
||||
public function testConstructorFail(): void
|
||||
{
|
||||
$this->expectException(ColorException::class);
|
||||
new Hue(400);
|
||||
}
|
||||
|
||||
public function testToInt(): void
|
||||
{
|
||||
$channel = new Hue(10);
|
||||
$this->assertEquals(10, $channel->toInt());
|
||||
}
|
||||
|
||||
public function testToString(): void
|
||||
{
|
||||
$channel = new Hue(10);
|
||||
$this->assertEquals("10", $channel->toString());
|
||||
$this->assertEquals("10", (string) $channel);
|
||||
}
|
||||
|
||||
public function testValue(): void
|
||||
{
|
||||
$channel = new Hue(10);
|
||||
|
16
tests/Colors/Hsv/Channels/SaturationTest.php
Normal file
16
tests/Colors/Hsv/Channels/SaturationTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Colors\Hsv\Channels;
|
||||
|
||||
use Intervention\Image\Colors\Hsv\Channels\Saturation;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
class SaturationTest extends TestCase
|
||||
{
|
||||
public function testMinMax(): void
|
||||
{
|
||||
$saturation = new Saturation(0);
|
||||
$this->assertEquals(0, $saturation->min());
|
||||
$this->assertEquals(100, $saturation->max());
|
||||
}
|
||||
}
|
16
tests/Colors/Hsv/Channels/ValueTest.php
Normal file
16
tests/Colors/Hsv/Channels/ValueTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Colors\Hsv\Channels;
|
||||
|
||||
use Intervention\Image\Colors\Hsv\Channels\Value;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
class ValueTest extends TestCase
|
||||
{
|
||||
public function testMinMax(): void
|
||||
{
|
||||
$saturation = new Value(0);
|
||||
$this->assertEquals(0, $saturation->min());
|
||||
$this->assertEquals(100, $saturation->max());
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ use Intervention\Image\Colors\Hsv\Channels\Saturation;
|
||||
use Intervention\Image\Colors\Hsv\Channels\Value;
|
||||
use Intervention\Image\Colors\Hsv\Color as Color;
|
||||
use Intervention\Image\Colors\Hsv\Colorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,12 @@ class ColorTest extends TestCase
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$color = Color::create('hsv(10, 20, 30)');
|
||||
$this->assertInstanceOf(Color::class, $color);
|
||||
}
|
||||
|
||||
public function testColorspace(): void
|
||||
{
|
||||
$color = new Color(0, 0, 0);
|
||||
@@ -41,6 +48,13 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals(10, $channel->value());
|
||||
}
|
||||
|
||||
public function testChannelNotFound(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30);
|
||||
$this->expectException(ColorException::class);
|
||||
$color->channel('none');
|
||||
}
|
||||
|
||||
public function testHueSaturationValueKey(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30);
|
||||
@@ -58,6 +72,12 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals([10, 20, 30], $color->toArray());
|
||||
}
|
||||
|
||||
public function testToHex(): void
|
||||
{
|
||||
$color = new Color(16, 100, 100);
|
||||
$this->assertEquals('ff4400', $color->toHex());
|
||||
}
|
||||
|
||||
public function testNormalize(): void
|
||||
{
|
||||
$color = new Color(180, 50, 25);
|
||||
|
@@ -32,6 +32,25 @@ class ChannelTest extends TestCase
|
||||
$channel = new Channel(normalized: 2);
|
||||
}
|
||||
|
||||
public function testConstructorFail(): void
|
||||
{
|
||||
$this->expectException(ColorException::class);
|
||||
new Channel(300);
|
||||
}
|
||||
|
||||
public function testToInt(): void
|
||||
{
|
||||
$channel = new Channel(255);
|
||||
$this->assertEquals(255, $channel->toInt());
|
||||
}
|
||||
|
||||
public function testToString(): void
|
||||
{
|
||||
$channel = new Channel(10);
|
||||
$this->assertEquals("10", $channel->toString());
|
||||
$this->assertEquals("10", (string) $channel);
|
||||
}
|
||||
|
||||
public function testValue(): void
|
||||
{
|
||||
$channel = new Channel(10);
|
||||
|
19
tests/Colors/Rgb/Channels/AlphaTest.php
Normal file
19
tests/Colors/Rgb/Channels/AlphaTest.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Colors\Rgb\Channels;
|
||||
|
||||
use Intervention\Image\Colors\Rgb\Channels\Alpha;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \Intervention\Image\Colors\Rgb\Channels\Alpha
|
||||
*/
|
||||
class AlphaTest extends TestCase
|
||||
{
|
||||
public function testToString(): void
|
||||
{
|
||||
$alpha = new Alpha(255 / 3);
|
||||
$this->assertEquals('0.333333', $alpha->toString());
|
||||
$this->assertEquals('0.333333', (string) $alpha);
|
||||
}
|
||||
}
|
@@ -9,6 +9,7 @@ use Intervention\Image\Colors\Rgb\Channels\Green;
|
||||
use Intervention\Image\Colors\Rgb\Channels\Blue;
|
||||
use Intervention\Image\Colors\Rgb\Color as Color;
|
||||
use Intervention\Image\Colors\Rgb\Colorspace as RgbColorspace;
|
||||
use Intervention\Image\Exceptions\ColorException;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -58,6 +59,13 @@ class ColorTest extends TestCase
|
||||
$this->assertEquals(10, $channel->value());
|
||||
}
|
||||
|
||||
public function testChannelNotFound(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30);
|
||||
$this->expectException(ColorException::class);
|
||||
$color->channel('none');
|
||||
}
|
||||
|
||||
public function testRedGreenBlue(): void
|
||||
{
|
||||
$color = new Color(10, 20, 30);
|
||||
@@ -80,6 +88,9 @@ class ColorTest extends TestCase
|
||||
$color = new Color(181, 55, 23);
|
||||
$this->assertEquals('b53717', $color->toHex());
|
||||
$this->assertEquals('#b53717', $color->toHex('#'));
|
||||
|
||||
$color = new Color(181, 55, 23, 51);
|
||||
$this->assertEquals('b5371733', $color->toHex());
|
||||
}
|
||||
|
||||
public function testNormalize(): void
|
||||
@@ -126,4 +137,13 @@ class ColorTest extends TestCase
|
||||
$this->assertInstanceOf(CmykColor::class, $converted);
|
||||
$this->assertEquals([0, 20, 20, 0], $converted->toArray());
|
||||
}
|
||||
|
||||
public function testIsGreyscale(): void
|
||||
{
|
||||
$color = new Color(255, 0, 100);
|
||||
$this->assertFalse($color->isGreyscale());
|
||||
|
||||
$color = new Color(50, 50, 50);
|
||||
$this->assertTrue($color->isGreyscale());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user