mirror of
https://github.com/Intervention/image.git
synced 2025-01-17 20:28:21 +01:00
Refactor tests to use data providers
This commit is contained in:
parent
2691d92ec5
commit
5ee087e711
@ -9,29 +9,44 @@ use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
|||||||
use Intervention\Image\Colors\Hsl\Color;
|
use Intervention\Image\Colors\Hsl\Color;
|
||||||
use Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder;
|
use Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder;
|
||||||
use Intervention\Image\Tests\BaseTestCase;
|
use Intervention\Image\Tests\BaseTestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
#[RequiresPhpExtension('gd')]
|
#[RequiresPhpExtension('gd')]
|
||||||
#[CoversClass(\Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder::class)]
|
#[CoversClass(\Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder::class)]
|
||||||
final class StringColorDecoderTest extends BaseTestCase
|
final class StringColorDecoderTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testDecode(): void
|
#[DataProvider('decodeDataProvier')]
|
||||||
|
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||||
{
|
{
|
||||||
$decoder = new StringColorDecoder();
|
$decoder = new StringColorDecoder();
|
||||||
|
$result = $decoder->decode($input);
|
||||||
|
$this->assertInstanceOf($classname, $result);
|
||||||
|
$this->assertEquals($channelValues, $result->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
$result = $decoder->decode('hsl(0,0,0)');
|
public static function decodeDataProvier(): array
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
{
|
||||||
$this->assertEquals([0, 0, 0], $result->toArray());
|
return [
|
||||||
|
[
|
||||||
$result = $decoder->decode('hsl(0, 100, 50)');
|
'hsl(0,0,0)',
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
Color::class,
|
||||||
$this->assertEquals([0, 100, 50], $result->toArray());
|
[0, 0, 0],
|
||||||
|
],
|
||||||
$result = $decoder->decode('hsl(360, 100, 50)');
|
[
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
'hsl(0, 100, 50)',
|
||||||
$this->assertEquals([360, 100, 50], $result->toArray());
|
Color::class,
|
||||||
|
[0, 100, 50],
|
||||||
$result = $decoder->decode('hsl(180, 100%, 50%)');
|
],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[
|
||||||
$this->assertEquals([180, 100, 50], $result->toArray());
|
'hsl(360, 100, 50)',
|
||||||
|
Color::class,
|
||||||
|
[360, 100, 50],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'hsl(180, 100%, 50%)',
|
||||||
|
Color::class,
|
||||||
|
[180, 100, 50],
|
||||||
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,50 +9,64 @@ use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
|||||||
use Intervention\Image\Colors\Hsv\Color;
|
use Intervention\Image\Colors\Hsv\Color;
|
||||||
use Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder;
|
use Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder;
|
||||||
use Intervention\Image\Tests\BaseTestCase;
|
use Intervention\Image\Tests\BaseTestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
#[RequiresPhpExtension('gd')]
|
#[RequiresPhpExtension('gd')]
|
||||||
#[CoversClass(\Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder::class)]
|
#[CoversClass(\Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder::class)]
|
||||||
final class StringColorDecoderTest extends BaseTestCase
|
final class StringColorDecoderTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testDecodeHsv(): void
|
#[DataProvider('decodeDataProvier')]
|
||||||
|
public function testDecodeHsv(string $input, string $classname, array $channelValues): void
|
||||||
{
|
{
|
||||||
$decoder = new StringColorDecoder();
|
$decoder = new StringColorDecoder();
|
||||||
$result = $decoder->decode('hsv(0,0,0)');
|
$result = $decoder->decode($input);
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf($classname, $result);
|
||||||
$this->assertEquals([0, 0, 0], $result->toArray());
|
$this->assertEquals($channelValues, $result->toArray());
|
||||||
|
|
||||||
$result = $decoder->decode('hsv(0, 100, 100)');
|
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
|
||||||
$this->assertEquals([0, 100, 100], $result->toArray());
|
|
||||||
|
|
||||||
$result = $decoder->decode('hsv(360, 100, 100)');
|
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
|
||||||
$this->assertEquals([360, 100, 100], $result->toArray());
|
|
||||||
|
|
||||||
|
|
||||||
$result = $decoder->decode('hsv(180, 100%, 100%)');
|
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
|
||||||
$this->assertEquals([180, 100, 100], $result->toArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDecodeHsb(): void
|
public static function decodeDataProvier(): array
|
||||||
{
|
{
|
||||||
$decoder = new StringColorDecoder();
|
return [
|
||||||
$result = $decoder->decode('hsb(0,0,0)');
|
[
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
'hsv(0,0,0)',
|
||||||
$this->assertEquals([0, 0, 0], $result->toArray());
|
Color::class,
|
||||||
|
[0, 0, 0],
|
||||||
$result = $decoder->decode('hsb(0, 100, 100)');
|
],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[
|
||||||
$this->assertEquals([0, 100, 100], $result->toArray());
|
'hsv(0, 100, 100)',
|
||||||
|
Color::class,
|
||||||
$result = $decoder->decode('hsb(360, 100, 100)');
|
[0, 100, 100],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
],
|
||||||
$this->assertEquals([360, 100, 100], $result->toArray());
|
[
|
||||||
|
'hsv(360, 100, 100)',
|
||||||
|
Color::class,
|
||||||
$result = $decoder->decode('hsb(180, 100%, 100%)');
|
[360, 100, 100],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
],
|
||||||
$this->assertEquals([180, 100, 100], $result->toArray());
|
[
|
||||||
|
'hsv(180, 100%, 100%)',
|
||||||
|
Color::class,
|
||||||
|
[180, 100, 100],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'hsb(0,0,0)',
|
||||||
|
Color::class,
|
||||||
|
[0, 0, 0],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'hsb(0, 100, 100)',
|
||||||
|
Color::class,
|
||||||
|
[0, 100, 100],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'hsb(360, 100, 100)',
|
||||||
|
Color::class,
|
||||||
|
[360, 100, 100],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'hsb(180, 100%, 100%)',
|
||||||
|
Color::class,
|
||||||
|
[180, 100, 100],
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,52 +9,74 @@ use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
|||||||
use Intervention\Image\Colors\Rgb\Color;
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
|
||||||
use Intervention\Image\Tests\BaseTestCase;
|
use Intervention\Image\Tests\BaseTestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
#[RequiresPhpExtension('gd')]
|
#[RequiresPhpExtension('gd')]
|
||||||
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder::class)]
|
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder::class)]
|
||||||
final class HexColorDecoderTest extends BaseTestCase
|
final class HexColorDecoderTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testDecode(): void
|
#[DataProvider('decodeDataProvier')]
|
||||||
|
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||||
{
|
{
|
||||||
$decoder = new HexColorDecoder();
|
$decoder = new HexColorDecoder();
|
||||||
$result = $decoder->decode('ccc');
|
$result = $decoder->decode($input);
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf($classname, $result);
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
$this->assertEquals($channelValues, $result->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
$result = $decoder->decode('ccff33');
|
public static function decodeDataProvier(): array
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
{
|
||||||
$this->assertEquals([204, 255, 51, 255], $result->toArray());
|
return [
|
||||||
|
[
|
||||||
$result = $decoder->decode('#ccc');
|
'ccc',
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
Color::class,
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
[204, 204, 204, 255]
|
||||||
|
],
|
||||||
$result = $decoder->decode('cccccc');
|
[
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
'ccff33',
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
Color::class,
|
||||||
|
[204, 255, 51, 255],
|
||||||
$result = $decoder->decode('#cccccc');
|
],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
'#ccc',
|
||||||
|
Color::class,
|
||||||
$result = $decoder->decode('#ccccccff');
|
[204, 204, 204, 255],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
],
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
[
|
||||||
|
'cccccc',
|
||||||
$result = $decoder->decode('#cccf');
|
Color::class,
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[204, 204, 204, 255],
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
],
|
||||||
|
[
|
||||||
$result = $decoder->decode('ccccccff');
|
'#cccccc',
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
Color::class,
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
[204, 204, 204, 255],
|
||||||
|
],
|
||||||
$result = $decoder->decode('cccf');
|
[
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
'#ccccccff',
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
Color::class,
|
||||||
|
[204, 204, 204, 255],
|
||||||
$result = $decoder->decode('#b53717aa');
|
],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[
|
||||||
$this->assertEquals([181, 55, 23, 170], $result->toArray());
|
'#cccf',
|
||||||
|
Color::class,
|
||||||
|
[204, 204, 204, 255],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'ccccccff',
|
||||||
|
Color::class,
|
||||||
|
[204, 204, 204, 255],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'cccf',
|
||||||
|
Color::class,
|
||||||
|
[204, 204, 204, 255],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#b53717aa',
|
||||||
|
Color::class,
|
||||||
|
[181, 55, 23, 170],
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,24 +9,39 @@ use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
|||||||
use Intervention\Image\Colors\Rgb\Color;
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
|
||||||
use Intervention\Image\Tests\BaseTestCase;
|
use Intervention\Image\Tests\BaseTestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
#[RequiresPhpExtension('gd')]
|
#[RequiresPhpExtension('gd')]
|
||||||
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\HtmlColorNameDecoder::class)]
|
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\HtmlColorNameDecoder::class)]
|
||||||
final class HtmlColornameDecoderTest extends BaseTestCase
|
final class HtmlColornameDecoderTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testDecode(): void
|
#[DataProvider('decodeDataProvier')]
|
||||||
|
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||||
{
|
{
|
||||||
$decoder = new HtmlColornameDecoder();
|
$decoder = new HtmlColornameDecoder();
|
||||||
$result = $decoder->decode('salmon');
|
$result = $decoder->decode($input);
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf($classname, $result);
|
||||||
$this->assertEquals([250, 128, 114, 255], $result->toArray());
|
$this->assertEquals($channelValues, $result->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
$result = $decoder->decode('khaki');
|
public static function decodeDataProvier(): array
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
{
|
||||||
$this->assertEquals([240, 230, 140, 255], $result->toArray());
|
return [
|
||||||
|
[
|
||||||
$result = $decoder->decode('peachpuff');
|
'salmon',
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
Color::class,
|
||||||
$this->assertEquals([255, 218, 185, 255], $result->toArray());
|
[250, 128, 114, 255],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'khaki',
|
||||||
|
Color::class,
|
||||||
|
[240, 230, 140, 255],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'peachpuff',
|
||||||
|
Color::class,
|
||||||
|
[255, 218, 185, 255],
|
||||||
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,44 +9,64 @@ use PHPUnit\Framework\Attributes\RequiresPhpExtension;
|
|||||||
use Intervention\Image\Colors\Rgb\Color;
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder;
|
use Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder;
|
||||||
use Intervention\Image\Tests\BaseTestCase;
|
use Intervention\Image\Tests\BaseTestCase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
|
||||||
#[RequiresPhpExtension('gd')]
|
#[RequiresPhpExtension('gd')]
|
||||||
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder::class)]
|
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\StringColorDecoder::class)]
|
||||||
final class StringColorDecoderTest extends BaseTestCase
|
final class StringColorDecoderTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testDecode(): void
|
#[DataProvider('decodeDataProvier')]
|
||||||
|
public function testDecode(string $input, string $classname, array $channelValues): void
|
||||||
{
|
{
|
||||||
$decoder = new StringColorDecoder();
|
$decoder = new StringColorDecoder();
|
||||||
$result = $decoder->decode('rgb(204, 204, 204)');
|
$result = $decoder->decode($input);
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf($classname, $result);
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
$this->assertEquals($channelValues, $result->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
$result = $decoder->decode('rgb(204,204,204)');
|
public static function decodeDataProvier(): array
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
{
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
return [
|
||||||
|
[
|
||||||
$result = $decoder->decode('rgb(100%,20%,0%)');
|
'rgb(204, 204, 204)',
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
Color::class,
|
||||||
$this->assertEquals([255, 51, 0, 255], $result->toArray());
|
[204, 204, 204, 255],
|
||||||
|
],
|
||||||
$result = $decoder->decode('rgb(100%,19.8064%,0.1239483%)');
|
[
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
'rgb(204,204,204)',
|
||||||
$this->assertEquals([255, 51, 0, 255], $result->toArray());
|
Color::class,
|
||||||
|
[204, 204, 204, 255],
|
||||||
$result = $decoder->decode('rgba(204, 204, 204, 1)');
|
],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[
|
||||||
$this->assertEquals([204, 204, 204, 255], $result->toArray());
|
'rgb(100%,20%,0%)',
|
||||||
|
Color::class,
|
||||||
$result = $decoder->decode('rgba(204,204,204,.2)');
|
[255, 51, 0, 255],
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
],
|
||||||
$this->assertEquals([204, 204, 204, 51], $result->toArray());
|
[
|
||||||
|
'rgb(100%,19.8064%,0.1239483%)',
|
||||||
$result = $decoder->decode('rgba(204,204,204,0.2)');
|
Color::class,
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
[255, 51, 0, 255],
|
||||||
$this->assertEquals([204, 204, 204, 51], $result->toArray());
|
],
|
||||||
|
[
|
||||||
$result = $decoder->decode('srgb(255, 0, 0)');
|
'rgba(204, 204, 204, 1)',
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
Color::class,
|
||||||
$this->assertEquals([255, 0, 0, 255], $result->toArray());
|
[204, 204, 204, 255],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rgba(204,204,204,.2)',
|
||||||
|
Color::class,
|
||||||
|
[204, 204, 204, 51],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rgba(204,204,204,0.2)',
|
||||||
|
Color::class,
|
||||||
|
[204, 204, 204, 51],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'srgb(255, 0, 0)',
|
||||||
|
Color::class,
|
||||||
|
[255, 0, 0, 255],
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user