Skip to content

Commit

Permalink
Optimize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 21, 2024
1 parent 65447d8 commit da4d538
Show file tree
Hide file tree
Showing 120 changed files with 292 additions and 185 deletions.
2 changes: 2 additions & 0 deletions tests/Feature/Gd/ConvertPngGif.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Intervention\Image\ImageManager;
use Intervention\Image\Tests\GdTestCase;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;

#[RequiresPhpExtension('gd')]
class ConvertPngGif extends GdTestCase
{
public function testConversionKeepsTransparency(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Imagick/ConvertPngGif.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Intervention\Image\ImageManager;
use Intervention\Image\Tests\ImagickTestCase;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;

#[RequiresPhpExtension('imagick')]
class ConvertPngGif extends ImagickTestCase
{
public function testConversionKeepsTransparency(): void
Expand Down
51 changes: 26 additions & 25 deletions tests/Unit/Colors/Cmyk/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,79 @@

namespace Intervention\Image\Tests\Unit\Colors\Cmyk;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Cmyk\Channels\Cyan as Channel;
use Intervention\Image\Colors\Cmyk\Channels\Cyan;
use Intervention\Image\Colors\Cmyk\Channels\Key;
use Intervention\Image\Colors\Cmyk\Channels\Magenta;
use Intervention\Image\Colors\Cmyk\Channels\Yellow;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Cmyk\Channels\Cyan::class)]
#[CoversClass(\Intervention\Image\Colors\Cmyk\Channels\Magenta::class)]
#[CoversClass(\Intervention\Image\Colors\Cmyk\Channels\Yellow::class)]
#[CoversClass(\Intervention\Image\Colors\Cmyk\Channels\Key::class)]
#[CoversClass(Cyan::class)]
#[CoversClass(Magenta::class)]
#[CoversClass(Yellow::class)]
#[CoversClass(Key::class)]
final class ChannelTest extends BaseTestCase
{
public function testConstructor(): void
{
$channel = new Channel(0);
$this->assertInstanceOf(Channel::class, $channel);
$channel = new Cyan(0);
$this->assertInstanceOf(Cyan::class, $channel);

$channel = new Channel(value: 0);
$this->assertInstanceOf(Channel::class, $channel);
$channel = new Cyan(value: 0);
$this->assertInstanceOf(Cyan::class, $channel);

$channel = new Channel(normalized: 0);
$this->assertInstanceOf(Channel::class, $channel);
$channel = new Cyan(normalized: 0);
$this->assertInstanceOf(Cyan::class, $channel);

$this->expectException(ColorException::class);
new Channel();
new Cyan();

$this->expectException(ColorException::class);
new Channel(normalized: 2);
new Cyan(normalized: 2);
}

public function testConstructorFail(): void
{
$this->expectException(ColorException::class);
new Channel(200);
new Cyan(200);
}

public function testToInt(): void
{
$channel = new Channel(10);
$channel = new Cyan(10);
$this->assertEquals(10, $channel->toInt());
}

public function testToString(): void
{
$channel = new Channel(10);
$channel = new Cyan(10);
$this->assertEquals("10", $channel->toString());
$this->assertEquals("10", (string) $channel);
}

public function testValue(): void
{
$channel = new Channel(10);
$channel = new Cyan(10);
$this->assertEquals(10, $channel->value());
}

public function testNormalize(): void
{
$channel = new Channel(100);
$channel = new Cyan(100);
$this->assertEquals(1, $channel->normalize());
$channel = new Channel(0);
$channel = new Cyan(0);
$this->assertEquals(0, $channel->normalize());
$channel = new Channel(20);
$channel = new Cyan(20);
$this->assertEquals(.2, $channel->normalize());
}

public function testValidate(): void
{
$this->expectException(ColorException::class);
new Channel(101);
new Cyan(101);

$this->expectException(ColorException::class);
new Channel(-1);
new Cyan(-1);
}
}
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Cmyk/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Intervention\Image\Tests\Unit\Colors\Cmyk;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Cmyk\Channels\Cyan;
use Intervention\Image\Colors\Cmyk\Channels\Key;
use Intervention\Image\Colors\Cmyk\Channels\Magenta;
Expand All @@ -15,8 +14,7 @@
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Cmyk\Color::class)]
#[CoversClass(Color::class)]
final class ColorTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Cmyk/ColorspaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Intervention\Image\Colors\Cmyk\Colorspace;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Cmyk\Colorspace::class)]
#[CoversClass(Colorspace::class)]
final class ColorspaceTest extends BaseTestCase
{
public function testColorFromNormalized(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Cmyk/Decoders/StringColorDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
namespace Intervention\Image\Tests\Unit\Colors\Cmyk\Decoders;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Cmyk\Color;
use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Tests\BaseTestCase;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder::class)]
#[CoversClass(StringColorDecoder::class)]
final class StringColorDecoderTest extends BaseTestCase
{
public function testDecode(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Colors/Hsl/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Hsl\Channels\Hue::class)]
#[CoversClass(\Intervention\Image\Colors\Hsl\Channels\Saturation::class)]
#[CoversClass(\Intervention\Image\Colors\Hsl\Channels\Luminance::class)]
#[CoversClass(Hue::class)]
#[CoversClass(Saturation::class)]
#[CoversClass(Luminance::class)]
final class ChannelTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Colors/Hsl/Channels/SaturationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Intervention\Image\Colors\Hsl\Channels\Saturation;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(Saturation::class)]
final class SaturationTest extends BaseTestCase
{
public function testMinMax(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Hsl/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Hsl\Color::class)]
#[CoversClass(Color::class)]
final class ColorTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Hsl/ColorspaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Intervention\Image\Colors\Hsl\Colorspace;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Hsl\Colorspace::class)]
#[CoversClass(Colorspace::class)]
final class ColorspaceTest extends BaseTestCase
{
public function testColorFromNormalized(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Hsl\Color;
use Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Hsl\Decoders\StringColorDecoder::class)]
#[CoversClass(StringColorDecoder::class)]
final class StringColorDecoderTest extends BaseTestCase
{
#[DataProvider('decodeDataProvier')]
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/Colors/Hsv/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
namespace Intervention\Image\Tests\Unit\Colors\Hsv;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Hsv\Channels\Hue;
use Intervention\Image\Colors\Hsv\Channels\Saturation;
use Intervention\Image\Colors\Hsv\Channels\Value;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Hsv\Channels\Hue::class)]
#[CoversClass(\Intervention\Image\Colors\Hsv\Channels\Saturation::class)]
#[CoversClass(\Intervention\Image\Colors\Hsv\Channels\Value::class)]
#[CoversClass(Hue::class)]
#[CoversClass(Saturation::class)]
#[CoversClass(Value::class)]
final class ChannelTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Colors/Hsv/Channels/SaturationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Intervention\Image\Colors\Hsv\Channels\Saturation;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(Saturation::class)]
final class SaturationTest extends BaseTestCase
{
public function testMinMax(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Colors/Hsv/Channels/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Intervention\Image\Colors\Hsv\Channels\Value;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(Value::class)]
final class ValueTest extends BaseTestCase
{
public function testMinMax(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Hsv/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Hsv\Color::class)]
#[CoversClass(Color::class)]
final class ColorTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Hsv/ColorspaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Intervention\Image\Colors\Hsv\Colorspace;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Hsv\Colorspace::class)]
#[CoversClass(Colorspace::class)]
final class ColorspaceTest extends BaseTestCase
{
public function testColorFromNormalized(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Hsv\Color;
use Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Hsv\Decoders\StringColorDecoder::class)]
#[CoversClass(StringColorDecoder::class)]
final class StringColorDecoderTest extends BaseTestCase
{
#[DataProvider('decodeDataProvier')]
Expand Down
11 changes: 6 additions & 5 deletions tests/Unit/Colors/Rgb/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace Intervention\Image\Tests\Unit\Colors\Rgb;

use Intervention\Image\Colors\Rgb\Channels\Blue;
use Intervention\Image\Colors\Rgb\Channels\Green;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Rgb\Channels\Red as Channel;
use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Rgb\Channels\Red::class)]
#[CoversClass(\Intervention\Image\Colors\Rgb\Channels\Green::class)]
#[CoversClass(\Intervention\Image\Colors\Rgb\Channels\Blue::class)]
#[CoversClass(Red::class)]
#[CoversClass(Green::class)]
#[CoversClass(Blue::class)]
final class ChannelTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Rgb/Channels/AlphaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Rgb\Channels\Alpha::class)]
#[CoversClass(Alpha::class)]
final class AlphaTest extends BaseTestCase
{
public function testToString(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Rgb/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Intervention\Image\Tests\Unit\Colors\Rgb;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
use Intervention\Image\Colors\Cmyk\Colorspace as CmykColorspace;
use Intervention\Image\Colors\Rgb\Channels\Red;
Expand All @@ -16,8 +15,7 @@
use Intervention\Image\Exceptions\ColorException;
use Intervention\Image\Tests\BaseTestCase;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Rgb\Color::class)]
#[CoversClass(Color::class)]
final class ColorTest extends BaseTestCase
{
public function testConstructor(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Colors/Rgb/ColorspaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Tests\BaseTestCase;

#[CoversClass(\Intervention\Image\Colors\Rgb\Colorspace::class)]
#[CoversClass(Colorspace::class)]
final class ColorspaceTest extends BaseTestCase
{
public function testColorFromNormalized(): void
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder::class)]
#[CoversClass(HexColorDecoder::class)]
final class HexColorDecoderTest extends BaseTestCase
{
#[DataProvider('decodeDataProvier')]
Expand Down
4 changes: 1 addition & 3 deletions tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\Colors\Rgb\Decoders\HtmlColornameDecoder;
use Intervention\Image\Tests\BaseTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Colors\Rgb\Decoders\HtmlColorNameDecoder::class)]
#[CoversClass(HtmlColorNameDecoder::class)]
final class HtmlColornameDecoderTest extends BaseTestCase
{
#[DataProvider('decodeDataProvier')]
Expand Down
Loading

0 comments on commit da4d538

Please sign in to comment.