diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7fdf0fbd..485f0dbf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -89,9 +89,6 @@ jobs: - name: Install dependencies run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction - - name: GD Version - run: php -r 'var_dump(gd_info());' - - name: Imagick Version run: php -r 'var_dump(Imagick::getVersion());' @@ -100,9 +97,3 @@ jobs: - name: Execute tests run: vendor/bin/phpunit --no-coverage - - - name: Run analyzer - run: vendor/bin/phpstan - - - name: Validate coding standards - run: vendor/bin/phpcs diff --git a/phpunit.dist.xml b/phpunit.dist.xml index c2ea5b34..c63e938f 100644 --- a/phpunit.dist.xml +++ b/phpunit.dist.xml @@ -15,9 +15,6 @@ ./tests/Unit - - ./tests/Feature - diff --git a/tests/Feature/Gd/ConvertPngGif.php b/tests/Feature/Gd/ConvertPngGif.php deleted file mode 100644 index 6e5eab7c..00000000 --- a/tests/Feature/Gd/ConvertPngGif.php +++ /dev/null @@ -1,22 +0,0 @@ -read( - $this->readTestImage('circle.png')->toGif() - ); - - $this->assertTransparency($converted->pickColor(0, 0)); - $this->assertColor(4, 2, 4, 255, $converted->pickColor(25, 25), 4); - } -} diff --git a/tests/Feature/Imagick/ConvertPngGif.php b/tests/Feature/Imagick/ConvertPngGif.php deleted file mode 100644 index d9bf11bf..00000000 --- a/tests/Feature/Imagick/ConvertPngGif.php +++ /dev/null @@ -1,22 +0,0 @@ -read( - $this->readTestImage('circle.png')->toGif() - ); - - $this->assertTransparency($converted->pickColor(0, 0)); - $this->assertColor(4, 2, 4, 255, $converted->pickColor(25, 25), 4); - } -} diff --git a/tests/Unit/CollectionTest.php b/tests/Unit/CollectionTest.php deleted file mode 100644 index 94334341..00000000 --- a/tests/Unit/CollectionTest.php +++ /dev/null @@ -1,180 +0,0 @@ -assertInstanceOf(Collection::class, $collection); - - $collection = Collection::create(['foo', 'bar', 'baz']); - $this->assertInstanceOf(Collection::class, $collection); - } - - public function testIterator(): void - { - $collection = new Collection(['foo', 'bar', 'baz']); - foreach ($collection as $key => $item) { - switch ($key) { - case 0: - $this->assertEquals('foo', $item); - break; - - case 1: - $this->assertEquals('bar', $item); - break; - - case 2: - $this->assertEquals('baz', $item); - break; - } - } - } - - public function testCount(): void - { - $collection = new Collection(['foo', 'bar', 'baz']); - $this->assertEquals(3, $collection->count()); - $this->assertEquals(3, count($collection)); - } - - public function testFilter(): void - { - $collection = new Collection(['foo', 'bar', 'baz']); - $this->assertEquals(3, $collection->count()); - $collection = $collection->filter(function ($text) { - return substr($text, 0, 1) == 'b'; - }); - $this->assertEquals(2, $collection->count()); - } - - public function testFirstLast(): void - { - $collection = new Collection(['foo', 'bar', 'baz']); - $this->assertEquals('foo', $collection->first()); - $this->assertEquals('baz', $collection->last()); - - $collection = new Collection(); - $this->assertNull($collection->first()); - $this->assertNull($collection->last()); - } - - public function testPush(): void - { - $collection = new Collection(['foo', 'bar', 'baz']); - $this->assertEquals(3, $collection->count()); - $result = $collection->push('test'); - $this->assertEquals(4, $collection->count()); - $this->assertInstanceOf(Collection::class, $result); - } - - public function testToArray(): void - { - $collection = new Collection(['foo', 'bar', 'baz']); - $this->assertEquals(['foo', 'bar', 'baz'], $collection->toArray()); - } - - public function testMap(): void - { - $collection = new Collection(['FOO', 'BAR', 'BAZ']); - $mapped = $collection->map(function ($item) { - return strtolower($item); - }); - $this->assertInstanceOf(Collection::class, $collection); - $this->assertInstanceOf(Collection::class, $mapped); - $this->assertEquals(['FOO', 'BAR', 'BAZ'], $collection->toArray()); - $this->assertEquals(['foo', 'bar', 'baz'], $mapped->toArray()); - } - - public function testGet(): void - { - $collection = new Collection([ - 'first', - 'second', - ['testx' => 'x'], - 'foo' => 'foo_value', - 'bar' => 'bar_value', - 'baz' => [ - 'test1' => '1', - 'test2' => '2', - 'test3' => [ - 'example' => 'value' - ] - ] - ]); - - $this->assertEquals('first', $collection->get(0)); - $this->assertEquals('second', $collection->get(1)); - $this->assertEquals('first', $collection->get('0')); - $this->assertEquals('second', $collection->get('1')); - $this->assertEquals('x', $collection->get('2.testx')); - $this->assertEquals('foo_value', $collection->get('foo')); - $this->assertEquals('bar_value', $collection->get('bar')); - $this->assertEquals('1', $collection->get('baz.test1')); - $this->assertEquals('2', $collection->get('baz.test2')); - $this->assertEquals('value', $collection->get('baz.test3.example')); - $this->assertEquals('value', $collection->get('baz.test3.example', 'default')); - $this->assertEquals('default', $collection->get('baz.test3.no', 'default')); - $this->assertEquals(['example' => 'value'], $collection->get('baz.test3')); - } - - public function testGetAtPosition(): void - { - $collection = new Collection([1, 2, 'foo' => 'bar']); - $this->assertEquals(1, $collection->getAtPosition(0)); - $this->assertEquals(2, $collection->getAtPosition(1)); - $this->assertEquals('bar', $collection->getAtPosition(2)); - $this->assertNull($collection->getAtPosition(3)); - $this->assertEquals('default', $collection->getAtPosition(3, 'default')); - } - - public function testGetAtPositionEmpty(): void - { - $collection = new Collection(); - $this->assertNull($collection->getAtPosition()); - $this->assertEquals('default', $collection->getAtPosition(3, 'default')); - } - - public function testEmpty(): void - { - $collection = new Collection([1, 2, 3]); - $this->assertEquals(3, $collection->count()); - $result = $collection->empty(); - $this->assertEquals(0, $collection->count()); - $this->assertEquals(0, $result->count()); - } - - public function testSlice(): void - { - $collection = new Collection(['a', 'b', 'c', 'd', 'e', 'f']); - $this->assertEquals(6, $collection->count()); - $result = $collection->slice(0, 3); - $this->assertEquals(['a', 'b', 'c'], $collection->toArray()); - $this->assertEquals(['a', 'b', 'c'], $result->toArray()); - $this->assertEquals('a', $result->get(0)); - $this->assertEquals('b', $result->get(1)); - $this->assertEquals('c', $result->get(2)); - - $result = $collection->slice(2, 1); - $this->assertEquals(['c'], $collection->toArray()); - $this->assertEquals(['c'], $result->toArray()); - $this->assertEquals('c', $result->get(0)); - } - - public function testSliceOutOfBounds(): void - { - $collection = new Collection(['a', 'b', 'c']); - $result = $collection->slice(6); - $this->assertEquals(0, $result->count()); - $this->assertEquals([], $result->toArray()); - } -} diff --git a/tests/Unit/Colors/Cmyk/ChannelTest.php b/tests/Unit/Colors/Cmyk/ChannelTest.php deleted file mode 100644 index 1f58747e..00000000 --- a/tests/Unit/Colors/Cmyk/ChannelTest.php +++ /dev/null @@ -1,81 +0,0 @@ -assertInstanceOf(Channel::class, $channel); - - $channel = new Channel(value: 0); - $this->assertInstanceOf(Channel::class, $channel); - - $channel = new Channel(normalized: 0); - $this->assertInstanceOf(Channel::class, $channel); - - $this->expectException(ColorException::class); - new Channel(); - - $this->expectException(ColorException::class); - 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); - $this->assertEquals(10, $channel->value()); - } - - public function testNormalize(): void - { - $channel = new Channel(100); - $this->assertEquals(1, $channel->normalize()); - $channel = new Channel(0); - $this->assertEquals(0, $channel->normalize()); - $channel = new Channel(20); - $this->assertEquals(.2, $channel->normalize()); - } - - public function testValidate(): void - { - $this->expectException(ColorException::class); - new Channel(101); - - $this->expectException(ColorException::class); - new Channel(-1); - } -} diff --git a/tests/Unit/Colors/Cmyk/ColorTest.php b/tests/Unit/Colors/Cmyk/ColorTest.php deleted file mode 100644 index 7fae9ea4..00000000 --- a/tests/Unit/Colors/Cmyk/ColorTest.php +++ /dev/null @@ -1,120 +0,0 @@ -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); - $this->assertInstanceOf(Colorspace::class, $color->colorspace()); - } - - public function testChannels(): void - { - $color = new Color(10, 20, 30, 40); - $this->assertIsArray($color->channels()); - $this->assertCount(4, $color->channels()); - } - - public function testChannel(): void - { - $color = new Color(10, 20, 30, 40); - $channel = $color->channel(Cyan::class); - $this->assertInstanceOf(Cyan::class, $channel); - $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); - $this->assertInstanceOf(Cyan::class, $color->cyan()); - $this->assertInstanceOf(Magenta::class, $color->magenta()); - $this->assertInstanceOf(Yellow::class, $color->yellow()); - $this->assertInstanceOf(Key::class, $color->key()); - $this->assertEquals(10, $color->cyan()->value()); - $this->assertEquals(20, $color->magenta()->value()); - $this->assertEquals(30, $color->yellow()->value()); - $this->assertEquals(40, $color->key()->value()); - } - - public function testToArray(): void - { - $color = new Color(10, 20, 30, 40); - $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); - $this->assertEquals([1.0, 0.5, 0.2, 0.0], $color->normalize()); - } - - public function testToString(): void - { - $color = new Color(100, 50, 20, 0); - $this->assertEquals('cmyk(100%, 50%, 20%, 0%)', (string) $color); - } - - public function testIsTransparent(): void - { - $color = new Color(100, 50, 50, 0); - $this->assertFalse($color->isTransparent()); - } - - public function testIsClear(): void - { - $color = new Color(0, 0, 0, 0); - $this->assertFalse($color->isClear()); - } -} diff --git a/tests/Unit/Colors/Cmyk/ColorspaceTest.php b/tests/Unit/Colors/Cmyk/ColorspaceTest.php deleted file mode 100644 index 83cf00d9..00000000 --- a/tests/Unit/Colors/Cmyk/ColorspaceTest.php +++ /dev/null @@ -1,88 +0,0 @@ -colorFromNormalized([0, 1, 0, 1]); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(100, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(100, $result->channel(Key::class)->value()); - } - - public function testImportRgbColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new RgbColor(255, 0, 255)); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(100, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(0, $result->channel(Key::class)->value()); - - $result = $colorspace->importColor(new RgbColor(127, 127, 127)); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(0, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(50, $result->channel(Key::class)->value()); - - $result = $colorspace->importColor(new RgbColor(127, 127, 127, 85)); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(0, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(50, $result->channel(Key::class)->value()); - } - - public function testImportHsvColor(): void - { - $colorspace = new Colorspace(); - $result = $colorspace->importColor(new HsvColor(0, 0, 50)); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(0, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(50, $result->channel(Key::class)->value()); - } - - public function testImportHslColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new HslColor(300, 100, 50)); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(100, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(0, $result->channel(Key::class)->value()); - - $result = $colorspace->importColor(new HslColor(0, 0, 50)); - $this->assertInstanceOf(CmykColor::class, $result); - $this->assertEquals(0, $result->channel(Cyan::class)->value()); - $this->assertEquals(0, $result->channel(Magenta::class)->value()); - $this->assertEquals(0, $result->channel(Yellow::class)->value()); - $this->assertEquals(50, $result->channel(Key::class)->value()); - } -} diff --git a/tests/Unit/Colors/Cmyk/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Cmyk/Decoders/StringColorDecoderTest.php deleted file mode 100644 index e24996b8..00000000 --- a/tests/Unit/Colors/Cmyk/Decoders/StringColorDecoderTest.php +++ /dev/null @@ -1,44 +0,0 @@ -decode('cmyk(0,0,0,0)'); - $this->assertInstanceOf(Color::class, $result); - $this->assertEquals([0, 0, 0, 0], $result->toArray()); - - $result = $decoder->decode('cmyk(0, 100, 100, 0)'); - $this->assertInstanceOf(Color::class, $result); - $this->assertEquals([0, 100, 100, 0], $result->toArray()); - - $result = $decoder->decode('cmyk(0, 100, 100, 0)'); - $this->assertInstanceOf(Color::class, $result); - $this->assertEquals([0, 100, 100, 0], $result->toArray()); - - $result = $decoder->decode('cmyk(0%, 100%, 100%, 0%)'); - $this->assertInstanceOf(Color::class, $result); - $this->assertEquals([0, 100, 100, 0], $result->toArray()); - } - - public function testDecodeInvalid(): void - { - $decoder = new StringColorDecoder(); - $this->expectException(DecoderException::class); - $decoder->decode(null); - } -} diff --git a/tests/Unit/Colors/Hsl/ChannelTest.php b/tests/Unit/Colors/Hsl/ChannelTest.php deleted file mode 100644 index 11166f27..00000000 --- a/tests/Unit/Colors/Hsl/ChannelTest.php +++ /dev/null @@ -1,94 +0,0 @@ -assertInstanceOf(Hue::class, $channel); - - $channel = new Hue(value: 0); - $this->assertInstanceOf(Hue::class, $channel); - - $channel = new Hue(normalized: 0); - $this->assertInstanceOf(Hue::class, $channel); - - $this->expectException(ColorException::class); - new Hue(); - - $this->expectException(ColorException::class); - 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); - $this->assertEquals(10, $channel->value()); - } - - public function testNormalize(): void - { - $channel = new Hue(360); - $this->assertEquals(1, $channel->normalize()); - $channel = new Hue(180); - $this->assertEquals(0.5, $channel->normalize()); - $channel = new Hue(0); - $this->assertEquals(0, $channel->normalize()); - $channel = new Luminance(90); - $this->assertEquals(.9, $channel->normalize()); - } - - public function testValidate(): void - { - $this->expectException(ColorException::class); - new Hue(361); - - $this->expectException(ColorException::class); - new Hue(-1); - - $this->expectException(ColorException::class); - new Saturation(101); - - $this->expectException(ColorException::class); - new Saturation(-1); - - $this->expectException(ColorException::class); - new Luminance(101); - - $this->expectException(ColorException::class); - new Luminance(-1); - } -} diff --git a/tests/Unit/Colors/Hsl/Channels/SaturationTest.php b/tests/Unit/Colors/Hsl/Channels/SaturationTest.php deleted file mode 100644 index a97da881..00000000 --- a/tests/Unit/Colors/Hsl/Channels/SaturationTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertEquals(0, $saturation->min()); - $this->assertEquals(100, $saturation->max()); - } -} diff --git a/tests/Unit/Colors/Hsl/ColorTest.php b/tests/Unit/Colors/Hsl/ColorTest.php deleted file mode 100644 index 749d21b0..00000000 --- a/tests/Unit/Colors/Hsl/ColorTest.php +++ /dev/null @@ -1,117 +0,0 @@ -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); - $this->assertInstanceOf(Colorspace::class, $color->colorspace()); - } - - public function testChannels(): void - { - $color = new Color(10, 20, 30); - $this->assertIsArray($color->channels()); - $this->assertCount(3, $color->channels()); - } - - public function testChannel(): void - { - $color = new Color(10, 20, 30); - $channel = $color->channel(Hue::class); - $this->assertInstanceOf(Hue::class, $channel); - $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); - $this->assertInstanceOf(Hue::class, $color->hue()); - $this->assertInstanceOf(Saturation::class, $color->saturation()); - $this->assertInstanceOf(Luminance::class, $color->luminance()); - $this->assertEquals(10, $color->hue()->value()); - $this->assertEquals(20, $color->saturation()->value()); - $this->assertEquals(30, $color->luminance()->value()); - } - - public function testToArray(): void - { - $color = new Color(10, 20, 30); - $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); - $this->assertEquals([.5, 0.5, 0.25], $color->normalize()); - } - - public function testToString(): void - { - $color = new Color(100, 50, 20, 0); - $this->assertEquals('hsl(100, 50%, 20%)', (string) $color); - } - - public function testIsGreyscale(): void - { - $color = new Color(0, 1, 0); - $this->assertFalse($color->isGreyscale()); - - $color = new Color(1, 0, 0); - $this->assertTrue($color->isGreyscale()); - - $color = new Color(0, 0, 1); - $this->assertTrue($color->isGreyscale()); - } - - public function testIsTransparent(): void - { - $color = new Color(0, 1, 0); - $this->assertFalse($color->isTransparent()); - } - - public function testIsClear(): void - { - $color = new Color(0, 1, 0); - $this->assertFalse($color->isClear()); - } -} diff --git a/tests/Unit/Colors/Hsl/ColorspaceTest.php b/tests/Unit/Colors/Hsl/ColorspaceTest.php deleted file mode 100644 index 11574012..00000000 --- a/tests/Unit/Colors/Hsl/ColorspaceTest.php +++ /dev/null @@ -1,87 +0,0 @@ -colorFromNormalized([1, 0, 1]); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(360, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(100, $result->channel(Luminance::class)->value()); - } - - public function testImportRgbColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new RgbColor(255, 0, 255)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(300, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - - $result = $colorspace->importColor(new RgbColor(127, 127, 127)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - - $result = $colorspace->importColor(new RgbColor(255, 0, 0, 85)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - } - - public function testImportCmykColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new CmykColor(0, 100, 0, 0)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(300, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - - $result = $colorspace->importColor(new CmykColor(0, 0, 0, 50)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - } - - public function testImportHsvColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new HsvColor(300, 100, 100)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(300, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - - $result = $colorspace->importColor(new HsvColor(0, 0, 50)); - $this->assertInstanceOf(HslColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Luminance::class)->value()); - } -} diff --git a/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php deleted file mode 100644 index 9eda0ef2..00000000 --- a/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php +++ /dev/null @@ -1,52 +0,0 @@ -decode($input); - $this->assertInstanceOf($classname, $result); - $this->assertEquals($channelValues, $result->toArray()); - } - - public static function decodeDataProvier(): array - { - return [ - [ - 'hsl(0,0,0)', - Color::class, - [0, 0, 0], - ], - [ - 'hsl(0, 100, 50)', - Color::class, - [0, 100, 50], - ], - [ - 'hsl(360, 100, 50)', - Color::class, - [360, 100, 50], - ], - [ - 'hsl(180, 100%, 50%)', - Color::class, - [180, 100, 50], - ] - ]; - } -} diff --git a/tests/Unit/Colors/Hsv/ChannelTest.php b/tests/Unit/Colors/Hsv/ChannelTest.php deleted file mode 100644 index e3aca085..00000000 --- a/tests/Unit/Colors/Hsv/ChannelTest.php +++ /dev/null @@ -1,96 +0,0 @@ -assertInstanceOf(Hue::class, $channel); - - $channel = new Hue(value: 0); - $this->assertInstanceOf(Hue::class, $channel); - - $channel = new Hue(normalized: 0); - $this->assertInstanceOf(Hue::class, $channel); - - $this->expectException(ColorException::class); - new Hue(); - - $this->expectException(ColorException::class); - 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); - $this->assertEquals(10, $channel->value()); - } - - public function testNormalize(): void - { - $channel = new Hue(360); - $this->assertEquals(1, $channel->normalize()); - $channel = new Hue(180); - $this->assertEquals(0.5, $channel->normalize()); - $channel = new Hue(0); - $this->assertEquals(0, $channel->normalize()); - $channel = new Hue(90); - $this->assertEquals(.25, $channel->normalize()); - } - - public function testValidate(): void - { - $this->expectException(ColorException::class); - new Hue(361); - - $this->expectException(ColorException::class); - new Hue(-1); - - $this->expectException(ColorException::class); - new Saturation(101); - - $this->expectException(ColorException::class); - new Saturation(-1); - - $this->expectException(ColorException::class); - new Value(101); - - $this->expectException(ColorException::class); - new Value(-1); - } -} diff --git a/tests/Unit/Colors/Hsv/Channels/SaturationTest.php b/tests/Unit/Colors/Hsv/Channels/SaturationTest.php deleted file mode 100644 index db273448..00000000 --- a/tests/Unit/Colors/Hsv/Channels/SaturationTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertEquals(0, $saturation->min()); - $this->assertEquals(100, $saturation->max()); - } -} diff --git a/tests/Unit/Colors/Hsv/Channels/ValueTest.php b/tests/Unit/Colors/Hsv/Channels/ValueTest.php deleted file mode 100644 index 7a49d592..00000000 --- a/tests/Unit/Colors/Hsv/Channels/ValueTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertEquals(0, $saturation->min()); - $this->assertEquals(100, $saturation->max()); - } -} diff --git a/tests/Unit/Colors/Hsv/ColorTest.php b/tests/Unit/Colors/Hsv/ColorTest.php deleted file mode 100644 index f4a270b2..00000000 --- a/tests/Unit/Colors/Hsv/ColorTest.php +++ /dev/null @@ -1,117 +0,0 @@ -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); - $this->assertInstanceOf(Colorspace::class, $color->colorspace()); - } - - public function testChannels(): void - { - $color = new Color(10, 20, 30); - $this->assertIsArray($color->channels()); - $this->assertCount(3, $color->channels()); - } - - public function testChannel(): void - { - $color = new Color(10, 20, 30); - $channel = $color->channel(Hue::class); - $this->assertInstanceOf(Hue::class, $channel); - $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); - $this->assertInstanceOf(Hue::class, $color->hue()); - $this->assertInstanceOf(Saturation::class, $color->saturation()); - $this->assertInstanceOf(Value::class, $color->value()); - $this->assertEquals(10, $color->hue()->value()); - $this->assertEquals(20, $color->saturation()->value()); - $this->assertEquals(30, $color->value()->value()); - } - - public function testToArray(): void - { - $color = new Color(10, 20, 30); - $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); - $this->assertEquals([.5, 0.5, 0.25], $color->normalize()); - } - - public function testToString(): void - { - $color = new Color(100, 50, 20, 0); - $this->assertEquals('hsv(100, 50%, 20%)', (string) $color); - } - - public function testIsGreyscale(): void - { - $color = new Color(0, 1, 0); - $this->assertFalse($color->isGreyscale()); - - $color = new Color(1, 0, 0); - $this->assertTrue($color->isGreyscale()); - - $color = new Color(0, 0, 1); - $this->assertTrue($color->isGreyscale()); - } - - public function testIsTransparent(): void - { - $color = new Color(1, 0, 0); - $this->assertFalse($color->isTransparent()); - } - - public function testIsClear(): void - { - $color = new Color(0, 1, 0); - $this->assertFalse($color->isClear()); - } -} diff --git a/tests/Unit/Colors/Hsv/ColorspaceTest.php b/tests/Unit/Colors/Hsv/ColorspaceTest.php deleted file mode 100644 index ed6867a1..00000000 --- a/tests/Unit/Colors/Hsv/ColorspaceTest.php +++ /dev/null @@ -1,87 +0,0 @@ -colorFromNormalized([1, 0, 1]); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(360, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(100, $result->channel(Value::class)->value()); - } - - public function testImportRgbColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new RgbColor(255, 0, 255)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(300, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(100, $result->channel(Value::class)->value()); - - $result = $colorspace->importColor(new RgbColor(127, 127, 127)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Value::class)->value()); - - $result = $colorspace->importColor(new RgbColor(127, 127, 127, 85)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Value::class)->value()); - } - - public function testImportCmykColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new CmykColor(0, 100, 0, 0)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(300, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(100, $result->channel(Value::class)->value()); - - $result = $colorspace->importColor(new CmykColor(0, 0, 0, 50)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Value::class)->value()); - } - - public function testImportHslColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new HslColor(300, 100, 50)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(300, $result->channel(Hue::class)->value()); - $this->assertEquals(100, $result->channel(Saturation::class)->value()); - $this->assertEquals(100, $result->channel(Value::class)->value()); - - $result = $colorspace->importColor(new HslColor(0, 0, 50)); - $this->assertInstanceOf(HsvColor::class, $result); - $this->assertEquals(0, $result->channel(Hue::class)->value()); - $this->assertEquals(0, $result->channel(Saturation::class)->value()); - $this->assertEquals(50, $result->channel(Value::class)->value()); - } -} diff --git a/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php deleted file mode 100644 index 8b146d28..00000000 --- a/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php +++ /dev/null @@ -1,72 +0,0 @@ -decode($input); - $this->assertInstanceOf($classname, $result); - $this->assertEquals($channelValues, $result->toArray()); - } - - public static function decodeDataProvier(): array - { - return [ - [ - 'hsv(0,0,0)', - Color::class, - [0, 0, 0], - ], - [ - 'hsv(0, 100, 100)', - Color::class, - [0, 100, 100], - ], - [ - 'hsv(360, 100, 100)', - Color::class, - [360, 100, 100], - ], - [ - '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], - ], - ]; - } -} diff --git a/tests/Unit/Colors/Rgb/ChannelTest.php b/tests/Unit/Colors/Rgb/ChannelTest.php deleted file mode 100644 index a61ef50d..00000000 --- a/tests/Unit/Colors/Rgb/ChannelTest.php +++ /dev/null @@ -1,80 +0,0 @@ -assertInstanceOf(Channel::class, $channel); - - $channel = new Channel(value: 0); - $this->assertInstanceOf(Channel::class, $channel); - - $channel = new Channel(normalized: 0); - $this->assertInstanceOf(Channel::class, $channel); - - $this->expectException(ColorException::class); - new Channel(); - - $this->expectException(ColorException::class); - 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); - $this->assertEquals(10, $channel->value()); - } - - public function testNormalize(): void - { - $channel = new Channel(255); - $this->assertEquals(1, $channel->normalize()); - $channel = new Channel(0); - $this->assertEquals(0, $channel->normalize()); - $channel = new Channel(51); - $this->assertEquals(.2, $channel->normalize()); - } - - public function testValidate(): void - { - $this->expectException(ColorException::class); - new Channel(256); - - $this->expectException(ColorException::class); - new Channel(-1); - } -} diff --git a/tests/Unit/Colors/Rgb/Channels/AlphaTest.php b/tests/Unit/Colors/Rgb/Channels/AlphaTest.php deleted file mode 100644 index cc6432bc..00000000 --- a/tests/Unit/Colors/Rgb/Channels/AlphaTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertEquals('0.333333', $alpha->toString()); - $this->assertEquals('0.333333', (string) $alpha); - } -} diff --git a/tests/Unit/Colors/Rgb/ColorTest.php b/tests/Unit/Colors/Rgb/ColorTest.php deleted file mode 100644 index 16bfd1ed..00000000 --- a/tests/Unit/Colors/Rgb/ColorTest.php +++ /dev/null @@ -1,181 +0,0 @@ -assertInstanceOf(Color::class, $color); - - $color = new Color(0, 0, 0, 0); - $this->assertInstanceOf(Color::class, $color); - } - - public function testCreate(): void - { - $color = Color::create('ccc'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([204, 204, 204, 255], $color->toArray()); - - $color = Color::create('rgba(10, 20, 30, .2)'); - $this->assertInstanceOf(Color::class, $color); - $this->assertEquals([10, 20, 30, 51], $color->toArray()); - } - - public function testColorspace(): void - { - $color = new Color(0, 0, 0); - $this->assertInstanceOf(RgbColorspace::class, $color->colorspace()); - } - - public function testChannels(): void - { - $color = new Color(10, 20, 30); - $this->assertIsArray($color->channels()); - $this->assertCount(4, $color->channels()); - } - - public function testChannel(): void - { - $color = new Color(10, 20, 30); - $channel = $color->channel(Red::class); - $this->assertInstanceOf(Red::class, $channel); - $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); - $this->assertInstanceOf(Red::class, $color->red()); - $this->assertInstanceOf(Green::class, $color->green()); - $this->assertInstanceOf(Blue::class, $color->blue()); - $this->assertEquals(10, $color->red()->value()); - $this->assertEquals(20, $color->green()->value()); - $this->assertEquals(30, $color->blue()->value()); - } - - public function testToArray(): void - { - $color = new Color(10, 20, 30); - $this->assertEquals([10, 20, 30, 255], $color->toArray()); - } - - public function testToHex(): void - { - $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 - { - $color = new Color(255, 0, 51); - $this->assertEquals([1.0, 0.0, 0.2, 1.0], $color->normalize()); - } - - public function testToString(): void - { - $color = new Color(181, 55, 23); - $this->assertEquals('rgb(181, 55, 23)', (string) $color); - } - - public function testConvertTo(): void - { - $color = new Color(0, 0, 0); - $converted = $color->convertTo(CmykColorspace::class); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 0, 0, 100], $converted->toArray()); - - $color = new Color(255, 255, 255); - $converted = $color->convertTo(CmykColorspace::class); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 0, 0, 0], $converted->toArray()); - - $color = new Color(255, 0, 0); - $converted = $color->convertTo(CmykColorspace::class); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 100, 100, 0], $converted->toArray()); - - $color = new Color(255, 0, 255); - $converted = $color->convertTo(CmykColorspace::class); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 100, 0, 0], $converted->toArray()); - - $color = new Color(255, 255, 0); - $converted = $color->convertTo(CmykColorspace::class); - $this->assertInstanceOf(CmykColor::class, $converted); - $this->assertEquals([0, 0, 100, 0], $converted->toArray()); - - $color = new Color(255, 204, 204); - $converted = $color->convertTo(CmykColorspace::class); - $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()); - } - - public function testIsTransparent(): void - { - $color = new Color(255, 255, 255); - $this->assertFalse($color->isTransparent()); - - $color = new Color(255, 255, 255, 255); - $this->assertFalse($color->isTransparent()); - - $color = new Color(255, 255, 255, 85); - $this->assertTrue($color->isTransparent()); - - $color = new Color(255, 255, 255, 0); - $this->assertTrue($color->isTransparent()); - } - - public function testIsClear(): void - { - $color = new Color(255, 255, 255); - $this->assertFalse($color->isClear()); - - $color = new Color(255, 255, 255, 255); - $this->assertFalse($color->isClear()); - - $color = new Color(255, 255, 255, 85); - $this->assertFalse($color->isClear()); - - $color = new Color(255, 255, 255, 0); - $this->assertTrue($color->isClear()); - } -} diff --git a/tests/Unit/Colors/Rgb/ColorspaceTest.php b/tests/Unit/Colors/Rgb/ColorspaceTest.php deleted file mode 100644 index 5d4d5ec8..00000000 --- a/tests/Unit/Colors/Rgb/ColorspaceTest.php +++ /dev/null @@ -1,83 +0,0 @@ -colorFromNormalized([1, 0, 1, 1]); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(255, $result->channel(Red::class)->value()); - $this->assertEquals(0, $result->channel(Green::class)->value()); - $this->assertEquals(255, $result->channel(Blue::class)->value()); - $this->assertEquals(255, $result->channel(Alpha::class)->value()); - } - - public function testImportCmykColor(): void - { - $colorspace = new Colorspace(); - $result = $colorspace->importColor(new CmykColor(0, 100, 0, 0)); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(255, $result->channel(Red::class)->value()); - $this->assertEquals(0, $result->channel(Green::class)->value()); - $this->assertEquals(255, $result->channel(Blue::class)->value()); - - $result = $colorspace->importColor(new CmykColor(0, 0, 0, 50)); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(127, $result->channel(Red::class)->value()); - $this->assertEquals(127, $result->channel(Green::class)->value()); - $this->assertEquals(127, $result->channel(Blue::class)->value()); - } - - public function testImportHsvColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new HsvColor(300, 100, 100)); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(255, $result->channel(Red::class)->value()); - $this->assertEquals(0, $result->channel(Green::class)->value()); - $this->assertEquals(255, $result->channel(Blue::class)->value()); - - $result = $colorspace->importColor(new HsvColor(0, 0, 50)); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(128, $result->channel(Red::class)->value()); - $this->assertEquals(128, $result->channel(Green::class)->value()); - $this->assertEquals(128, $result->channel(Blue::class)->value()); - } - - public function testImportHslColor(): void - { - $colorspace = new Colorspace(); - - $result = $colorspace->importColor(new HslColor(300, 100, 50)); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(255, $result->channel(Red::class)->value()); - $this->assertEquals(0, $result->channel(Green::class)->value()); - $this->assertEquals(255, $result->channel(Blue::class)->value()); - - $result = $colorspace->importColor(new HslColor(0, 0, 50)); - $this->assertInstanceOf(RgbColor::class, $result); - $this->assertEquals(128, $result->channel(Red::class)->value()); - $this->assertEquals(128, $result->channel(Green::class)->value()); - $this->assertEquals(128, $result->channel(Blue::class)->value()); - } -} diff --git a/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php b/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php deleted file mode 100644 index fbe13779..00000000 --- a/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php +++ /dev/null @@ -1,82 +0,0 @@ -decode($input); - $this->assertInstanceOf($classname, $result); - $this->assertEquals($channelValues, $result->toArray()); - } - - public static function decodeDataProvier(): array - { - return [ - [ - 'ccc', - Color::class, - [204, 204, 204, 255] - ], - [ - 'ccff33', - Color::class, - [204, 255, 51, 255], - ], - [ - '#ccc', - Color::class, - [204, 204, 204, 255], - ], - [ - 'cccccc', - Color::class, - [204, 204, 204, 255], - ], - [ - '#cccccc', - Color::class, - [204, 204, 204, 255], - ], - [ - '#ccccccff', - Color::class, - [204, 204, 204, 255], - ], - [ - '#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], - ], - ]; - } -} diff --git a/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php b/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php deleted file mode 100644 index afe418e0..00000000 --- a/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php +++ /dev/null @@ -1,47 +0,0 @@ -decode($input); - $this->assertInstanceOf($classname, $result); - $this->assertEquals($channelValues, $result->toArray()); - } - - public static function decodeDataProvier(): array - { - return [ - [ - 'salmon', - Color::class, - [250, 128, 114, 255], - ], - [ - 'khaki', - Color::class, - [240, 230, 140, 255], - ], - [ - 'peachpuff', - Color::class, - [255, 218, 185, 255], - ] - ]; - } -} diff --git a/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php deleted file mode 100644 index bf135325..00000000 --- a/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php +++ /dev/null @@ -1,72 +0,0 @@ -decode($input); - $this->assertInstanceOf($classname, $result); - $this->assertEquals($channelValues, $result->toArray()); - } - - public static function decodeDataProvier(): array - { - return [ - [ - 'rgb(204, 204, 204)', - Color::class, - [204, 204, 204, 255], - ], - [ - 'rgb(204,204,204)', - Color::class, - [204, 204, 204, 255], - ], - [ - 'rgb(100%,20%,0%)', - Color::class, - [255, 51, 0, 255], - ], - [ - 'rgb(100%,19.8064%,0.1239483%)', - Color::class, - [255, 51, 0, 255], - ], - [ - 'rgba(204, 204, 204, 1)', - Color::class, - [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], - ], - ]; - } -} diff --git a/tests/Unit/ConfigTest.php b/tests/Unit/ConfigTest.php deleted file mode 100644 index 6a1683bd..00000000 --- a/tests/Unit/ConfigTest.php +++ /dev/null @@ -1,83 +0,0 @@ -assertInstanceOf(Config::class, $config); - - $this->assertTrue($config->autoOrientation); - $this->assertTrue($config->decodeAnimation); - $this->assertEquals('ffffff', $config->blendingColor); - - $config = new Config( - autoOrientation: false, - decodeAnimation: false, - blendingColor: 'f00', - ); - $this->assertInstanceOf(Config::class, $config); - - $this->assertFalse($config->autoOrientation); - $this->assertFalse($config->decodeAnimation); - $this->assertEquals('f00', $config->blendingColor); - } - - public function testGetSetOptions(): void - { - $config = new Config(); - $this->assertTrue($config->autoOrientation); - $this->assertTrue($config->decodeAnimation); - $this->assertEquals('ffffff', $config->blendingColor); - - $result = $config->setOptions( - autoOrientation: false, - decodeAnimation: false, - blendingColor: 'f00', - ); - - $this->assertFalse($config->autoOrientation); - $this->assertFalse($config->decodeAnimation); - $this->assertEquals('f00', $config->blendingColor); - - $this->assertFalse($result->autoOrientation); - $this->assertFalse($result->decodeAnimation); - $this->assertEquals('f00', $result->blendingColor); - - $result = $config->setOptions(blendingColor: '000'); - - $this->assertFalse($config->autoOrientation); - $this->assertFalse($config->decodeAnimation); - $this->assertEquals('000', $config->blendingColor); - - $this->assertFalse($result->autoOrientation); - $this->assertFalse($result->decodeAnimation); - $this->assertEquals('000', $result->blendingColor); - } - - public function testSetOptionsWithArray(): void - { - $config = new Config(); - $result = $config->setOptions([ - 'autoOrientation' => false, - 'decodeAnimation' => false, - 'blendingColor' => 'f00', - ]); - - $this->assertFalse($config->autoOrientation); - $this->assertFalse($config->decodeAnimation); - $this->assertEquals('f00', $config->blendingColor); - $this->assertFalse($result->autoOrientation); - $this->assertFalse($result->decodeAnimation); - $this->assertEquals('f00', $result->blendingColor); - } -} diff --git a/tests/Unit/Drivers/AbstractDecoderTest.php b/tests/Unit/Drivers/AbstractDecoderTest.php deleted file mode 100644 index 2a9ff77f..00000000 --- a/tests/Unit/Drivers/AbstractDecoderTest.php +++ /dev/null @@ -1,125 +0,0 @@ -assertFalse($decoder->isGifFormat($this->getTestResourceData('exif.jpg'))); - $this->assertTrue($decoder->isGifFormat($this->getTestResourceData('red.gif'))); - } - - public function testIsFile(): void - { - $decoder = Mockery::mock(AbstractDecoder::class); - $this->assertTrue($decoder->isFile($this->getTestResourcePath())); - $this->assertFalse($decoder->isFile('non-existent-file')); - $this->assertFalse($decoder->isFile(new stdClass())); - $this->assertFalse($decoder->isFile(str_repeat('o', PHP_MAXPATHLEN + 1))); - $this->assertFalse($decoder->isFile(__DIR__)); - } - - public function testExtractExifDataFromBinary(): void - { - $source = $this->getTestResourceData('exif.jpg'); - $pointer = $this->getTestResourcePointer('exif.jpg'); - $decoder = Mockery::mock(AbstractDecoder::class); - $decoder->shouldReceive('buildFilePointer')->with($source)->andReturn($pointer); - $result = $decoder->extractExifData($source); - $this->assertInstanceOf(CollectionInterface::class, $result); - $this->assertEquals('Oliver Vogel', $result->get('IFD0.Artist')); - } - - public function testExtractExifDataFromPath(): void - { - $decoder = Mockery::mock(AbstractDecoder::class); - $result = $decoder->extractExifData($this->getTestResourcePath('exif.jpg')); - $this->assertInstanceOf(CollectionInterface::class, $result); - $this->assertEquals('Oliver Vogel', $result->get('IFD0.Artist')); - } - - public function testParseDataUri(): void - { - $decoder = new class () extends AbstractDecoder - { - public function parse(mixed $input): object - { - return parent::parseDataUri($input); - } - - public function decode(mixed $input): ImageInterface|ColorInterface - { - throw new Exception(''); - } - }; - - $result = $decoder->parse( - 'data:image/gif;foo=bar;base64,R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7' - ); - - $this->assertTrue($result->isValid()); - $this->assertEquals('image/gif', $result->mediaType()); - $this->assertTrue($result->hasMediaType()); - $this->assertTrue($result->isBase64Encoded()); - $this->assertEquals( - 'R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7', - $result->data() - ); - - $result = $decoder->parse('data:text/plain;charset=utf-8,test'); - $this->assertTrue($result->isValid()); - $this->assertEquals('text/plain', $result->mediaType()); - $this->assertTrue($result->hasMediaType()); - $this->assertFalse($result->isBase64Encoded()); - $this->assertEquals('test', $result->data()); - - $result = $decoder->parse('data:;charset=utf-8,'); - $this->assertTrue($result->isValid()); - $this->assertNull($result->mediaType()); - $this->assertFalse($result->hasMediaType()); - $this->assertFalse($result->isBase64Encoded()); - $this->assertNull($result->data()); - } - - public function testIsValidBase64(): void - { - $decoder = new class () extends AbstractDecoder - { - public function isValid(mixed $input): bool - { - return parent::isValidBase64($input); - } - - public function decode(mixed $input): ImageInterface|ColorInterface - { - throw new Exception(''); - } - }; - - $this->assertTrue( - $decoder->isValid('R0lGODdhAwADAKIAAAQyrKTy/ByS7AQytLT2/AAAAAAAAAAAACwAAAAAAwADAAADBhgU0gMgAQA7') - ); - $this->assertFalse( - $decoder->isValid('foo') - ); - - $this->assertFalse( - $decoder->isValid(new stdClass()) - ); - } -} diff --git a/tests/Unit/Drivers/AbstractEncoderTest.php b/tests/Unit/Drivers/AbstractEncoderTest.php deleted file mode 100644 index 26797b78..00000000 --- a/tests/Unit/Drivers/AbstractEncoderTest.php +++ /dev/null @@ -1,26 +0,0 @@ -makePartial(); - $image = Mockery::mock(ImageInterface::class); - $encoded = Mockery::mock(EncodedImage::class); - $image->shouldReceive('encode')->andReturn($encoded); - $result = $encoder->encode($image); - $this->assertInstanceOf(EncodedImage::class, $result); - } -} diff --git a/tests/Unit/Drivers/AbstractFontProcessorTest.php b/tests/Unit/Drivers/AbstractFontProcessorTest.php deleted file mode 100644 index ac819563..00000000 --- a/tests/Unit/Drivers/AbstractFontProcessorTest.php +++ /dev/null @@ -1,111 +0,0 @@ -getTestResourcePath('test.ttf'))) - ->setWrapWidth(20) - ->setSize(50) - ->setLineHeight(1.25) - ->setAlignment('center'); - - $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); - - $processor - ->shouldReceive('boxSize') - ->with('T', $font) - ->andReturn(new Rectangle(12, 6)); - $processor - ->shouldReceive('boxSize') - ->with('Hy', $font) - ->andReturn(new Rectangle(24, 6)); - - $processor - ->shouldReceive('boxSize') - ->with('AAAA', $font) - ->andReturn(new Rectangle(24, 6, new Point(1000, 0))); - - $processor - ->shouldReceive('boxSize') - ->with('AAAA BBBB', $font) - ->andReturn(new Rectangle(24, 6)); - - $processor - ->shouldReceive('boxSize') - ->with('BBBB', $font) - ->andReturn(new Rectangle(24, 6, new Point(2000, 0))); - - $processor - ->shouldReceive('boxSize') - ->with('BBBB CCCC', $font) - ->andReturn(new Rectangle(24, 6)); - - $processor - ->shouldReceive('boxSize') - ->with('CCCC', $font) - ->andReturn(new Rectangle(24, 6, new Point(3000, 0))); - - $processor - ->shouldReceive('boxSize') - ->with($text, $font) - ->andReturn(new Rectangle(100, 25, new Point(10, 0))); - - $block = $processor->textBlock($text, $font, new Point(0, 0)); - - $this->assertInstanceOf(TextBlock::class, $block); - $this->assertEquals(3, $block->count()); - $this->assertEquals(-512, $block->getAtPosition(0)->position()->x()); - $this->assertEquals(-16, $block->getAtPosition(0)->position()->y()); - $this->assertEquals(-1012, $block->getAtPosition(1)->position()->x()); - $this->assertEquals(-8, $block->getAtPosition(1)->position()->y()); - $this->assertEquals(-1512, $block->getAtPosition(2)->position()->x()); - $this->assertEquals(0, $block->getAtPosition(2)->position()->y()); - } - - public function testNativeFontSize(): void - { - $font = (new Font($this->getTestResourcePath('test.ttf')))->setSize(32); - $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); - $this->assertEquals(32, $processor->nativeFontSize($font)); - } - - public function testTypographicalSize(): void - { - $font = new Font($this->getTestResourcePath('test.ttf')); - $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); - $processor->shouldReceive('boxSize')->with('Hy', $font)->andReturn(new Rectangle(24, 6)); - $this->assertEquals(6, $processor->typographicalSize($font)); - } - - public function testCapHeight(): void - { - $font = new Font($this->getTestResourcePath('test.ttf')); - $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); - $processor->shouldReceive('boxSize')->with('T', $font)->andReturn(new Rectangle(24, 6)); - $this->assertEquals(6, $processor->capHeight($font)); - } - - public function testLeading(): void - { - $font = (new Font($this->getTestResourcePath('test.ttf')))->setLineHeight(3); - $processor = Mockery::mock(AbstractFontProcessor::class)->makePartial(); - $processor->shouldReceive('boxSize')->with('Hy', $font)->andReturn(new Rectangle(24, 6)); - $this->assertEquals(18, $processor->leading($font)); - } -} diff --git a/tests/Unit/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php b/tests/Unit/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php deleted file mode 100644 index 1b345ddc..00000000 --- a/tests/Unit/Drivers/Gd/Analyzers/ColorspaceAnalyzerTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new ColorspaceAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(ColorspaceInterface::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Analyzers/HeightAnalyzerTest.php b/tests/Unit/Drivers/Gd/Analyzers/HeightAnalyzerTest.php deleted file mode 100644 index a13c674e..00000000 --- a/tests/Unit/Drivers/Gd/Analyzers/HeightAnalyzerTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new HeightAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertEquals(16, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php b/tests/Unit/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php deleted file mode 100644 index 7257d02c..00000000 --- a/tests/Unit/Drivers/Gd/Analyzers/PixelColorAnalyzerTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new PixelColorAnalyzer(0, 0); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(ColorInterface::class, $result); - $this->assertEquals('b4e000', $result->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Analyzers/PixelColorsAnalyzerTest.php b/tests/Unit/Drivers/Gd/Analyzers/PixelColorsAnalyzerTest.php deleted file mode 100644 index c895712e..00000000 --- a/tests/Unit/Drivers/Gd/Analyzers/PixelColorsAnalyzerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new PixelColorsAnalyzer(0, 0); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(Collection::class, $result); - $this->assertInstanceOf(ColorInterface::class, $result->first()); - $this->assertEquals('b4e000', $result->first()->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php b/tests/Unit/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php deleted file mode 100644 index f6068457..00000000 --- a/tests/Unit/Drivers/Gd/Analyzers/ResolutionAnalyzerTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new ResolutionAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(Resolution::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Analyzers/WidthAnalyzerTest.php b/tests/Unit/Drivers/Gd/Analyzers/WidthAnalyzerTest.php deleted file mode 100644 index 7caea47b..00000000 --- a/tests/Unit/Drivers/Gd/Analyzers/WidthAnalyzerTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new WidthAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertEquals(16, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/ClonerTest.php b/tests/Unit/Drivers/Gd/ClonerTest.php deleted file mode 100644 index 7fd39699..00000000 --- a/tests/Unit/Drivers/Gd/ClonerTest.php +++ /dev/null @@ -1,71 +0,0 @@ -getTestResourcePath('gradient.gif')); - $clone = Cloner::clone($gd); - - $this->assertEquals(16, imagesx($gd)); - $this->assertEquals(16, imagesy($gd)); - $this->assertEquals(16, imagesx($clone)); - $this->assertEquals(16, imagesy($clone)); - - $this->assertEquals( - imagecolorsforindex($gd, imagecolorat($gd, 10, 10)), - imagecolorsforindex($clone, imagecolorat($clone, 10, 10)) - ); - } - - public function testCloneEmpty(): void - { - $gd = imagecreatefromgif($this->getTestResourcePath('gradient.gif')); - $clone = Cloner::cloneEmpty($gd, new Rectangle(12, 12), new Color(255, 0, 0, 0)); - - $this->assertEquals(16, imagesx($gd)); - $this->assertEquals(16, imagesy($gd)); - $this->assertEquals(12, imagesx($clone)); - $this->assertEquals(12, imagesy($clone)); - - $this->assertEquals( - ['red' => 0, 'green' => 255, 'blue' => 2, 'alpha' => 0], - imagecolorsforindex($gd, imagecolorat($gd, 10, 10)), - ); - - $this->assertEquals( - ['red' => 255, 'green' => 0, 'blue' => 0, 'alpha' => 127], - imagecolorsforindex($clone, imagecolorat($clone, 10, 10)) - ); - } - - public function testCloneBlended(): void - { - $gd = imagecreatefromgif($this->getTestResourcePath('gradient.gif')); - $clone = Cloner::cloneBlended($gd, new Color(255, 0, 255, 255)); - - $this->assertEquals(16, imagesx($gd)); - $this->assertEquals(16, imagesy($gd)); - $this->assertEquals(16, imagesx($clone)); - $this->assertEquals(16, imagesy($clone)); - - $this->assertEquals( - ['red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127], - imagecolorsforindex($gd, imagecolorat($gd, 1, 0)), - ); - - $this->assertEquals( - ['red' => 255, 'green' => 0, 'blue' => 255, 'alpha' => 0], - imagecolorsforindex($clone, imagecolorat($clone, 1, 0)) - ); - } -} diff --git a/tests/Unit/Drivers/Gd/ColorProcessorTest.php b/tests/Unit/Drivers/Gd/ColorProcessorTest.php deleted file mode 100644 index 8e214c93..00000000 --- a/tests/Unit/Drivers/Gd/ColorProcessorTest.php +++ /dev/null @@ -1,42 +0,0 @@ -colorToNative(new Color(255, 55, 0, 255)); - $this->assertEquals(16725760, $result); - } - - public function testNativeToColor(): void - { - $processor = new ColorProcessor(); - $result = $processor->nativeToColor(16725760); - $this->assertInstanceOf(Color::class, $result); - $this->assertEquals(255, $result->channel(Red::class)->value()); - $this->assertEquals(55, $result->channel(Green::class)->value()); - $this->assertEquals(0, $result->channel(Blue::class)->value()); - $this->assertEquals(255, $result->channel(Alpha::class)->value()); - } - - public function testNativeToColorInvalid(): void - { - $processor = new ColorProcessor(); - $this->expectException(ColorException::class); - $processor->nativeToColor('test'); - } -} diff --git a/tests/Unit/Drivers/Gd/CoreTest.php b/tests/Unit/Drivers/Gd/CoreTest.php deleted file mode 100644 index c6cfb73a..00000000 --- a/tests/Unit/Drivers/Gd/CoreTest.php +++ /dev/null @@ -1,132 +0,0 @@ -core = new Core([ - new Frame(imagecreatetruecolor(3, 2)), - new Frame(imagecreatetruecolor(3, 2)), - new Frame(imagecreatetruecolor(3, 2)), - ]); - } - - public function getTestFrame(): Frame - { - return new Frame(imagecreatetruecolor(3, 2)); - } - - public function testAdd(): void - { - $this->assertEquals(3, $this->core->count()); - $result = $this->core->add($this->getTestFrame()); - $this->assertEquals(4, $this->core->count()); - $this->assertInstanceOf(Core::class, $result); - } - - public function testSetNative(): void - { - $gd1 = imagecreatetruecolor(3, 2); - $gd2 = imagecreatetruecolor(3, 2); - $core = new Core([new Frame($gd1)]); - $this->assertEquals($gd1, $core->native()); - $core->setNative($gd2); - $this->assertEquals($gd2, $core->native()); - } - - public function testCount(): void - { - $this->assertEquals(3, $this->core->count()); - } - - public function testIterator(): void - { - foreach ($this->core as $frame) { - $this->assertInstanceOf(Frame::class, $frame); - } - } - - public function testNative(): void - { - $this->assertInstanceOf(GdImage::class, $this->core->native()); - } - - public function testFrame(): void - { - $this->assertInstanceOf(Frame::class, $this->core->frame(0)); - $this->assertInstanceOf(Frame::class, $this->core->frame(1)); - $this->assertInstanceOf(Frame::class, $this->core->frame(2)); - $this->expectException(AnimationException::class); - $this->core->frame(3); - } - - public function testSetGetLoops(): void - { - $this->assertEquals(0, $this->core->loops()); - $result = $this->core->setLoops(12); - $this->assertInstanceOf(Core::class, $result); - $this->assertEquals(12, $this->core->loops()); - } - - public function testHas(): void - { - $this->assertTrue($this->core->has(0)); - $this->assertTrue($this->core->has(1)); - $this->assertTrue($this->core->has(2)); - $this->assertFalse($this->core->has(3)); - } - - public function testPush(): void - { - $this->assertEquals(3, $this->core->count()); - $result = $this->core->push($this->getTestFrame()); - $this->assertEquals(4, $this->core->count()); - $this->assertEquals(4, $result->count()); - } - - public function testGet(): void - { - $this->assertInstanceOf(Frame::class, $this->core->get(0)); - $this->assertInstanceOf(Frame::class, $this->core->get(1)); - $this->assertInstanceOf(Frame::class, $this->core->get(2)); - $this->assertNull($this->core->get(3)); - $this->assertEquals('foo', $this->core->get(3, 'foo')); - } - - public function testEmpty(): void - { - $result = $this->core->empty(); - $this->assertEquals(0, $this->core->count()); - $this->assertEquals(0, $result->count()); - } - - public function testSlice(): void - { - $this->assertEquals(3, $this->core->count()); - $result = $this->core->slice(1, 2); - $this->assertEquals(2, $this->core->count()); - $this->assertEquals(2, $result->count()); - } - - public function testFirst(): void - { - $this->assertInstanceOf(Frame::class, $this->core->first()); - } - - public function testLast(): void - { - $this->assertInstanceOf(Frame::class, $this->core->last()); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/AbstractDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/AbstractDecoderTest.php deleted file mode 100644 index 03ecf5d4..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/AbstractDecoderTest.php +++ /dev/null @@ -1,31 +0,0 @@ -makePartial(); - $this->assertEquals( - MediaType::IMAGE_JPEG, - $decoder->getMediaTypeByFilePath($this->getTestResourcePath('test.jpg')) - ); - } - - public function testGetMediaTypeFromFileBinary(): void - { - $decoder = Mockery::mock(AbstractDecoder::class)->makePartial(); - $this->assertEquals( - MediaType::IMAGE_JPEG, - $decoder->getMediaTypeByBinary($this->getTestResourceData('test.jpg')), - ); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/Base64ImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/Base64ImageDecoderTest.php deleted file mode 100644 index ff1bcc81..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/Base64ImageDecoderTest.php +++ /dev/null @@ -1,41 +0,0 @@ -decoder = new Base64ImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode( - base64_encode($this->getTestResourceData('blue.gif')) - ); - - $this->assertInstanceOf(Image::class, $result); - } - - public function testDecoderInvalid(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode('test'); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/BinaryImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/BinaryImageDecoderTest.php deleted file mode 100644 index f7309f40..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/BinaryImageDecoderTest.php +++ /dev/null @@ -1,62 +0,0 @@ -decoder = new BinaryImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecodePng(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('tile.png'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertCount(1, $image); - } - - public function testDecodeGif(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('red.gif'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertCount(1, $image); - } - - public function testDecodeAnimatedGif(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('cats.gif'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(75, $image->width()); - $this->assertEquals(50, $image->height()); - $this->assertCount(4, $image); - } - - public function testDecodeJpegWithExif(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('exif.jpg'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertCount(1, $image); - $this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist')); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/DataUriImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/DataUriImageDecoderTest.php deleted file mode 100644 index 8c2f604e..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/DataUriImageDecoderTest.php +++ /dev/null @@ -1,54 +0,0 @@ -decoder = new DataUriImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode( - sprintf('data:image/jpeg;base64,%s', base64_encode($this->getTestResourceData('blue.gif'))) - ); - - $this->assertInstanceOf(Image::class, $result); - } - - public function testDecoderNonString(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode(new stdClass()); - } - - public function testDecoderInvalid(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode('invalid'); - } - - public function testDecoderNonImage(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode('data:text/plain;charset=utf-8,test'); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php deleted file mode 100644 index f75762f1..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/EncodedImageObjectDecoderTest.php +++ /dev/null @@ -1,32 +0,0 @@ -decoder = new EncodedImageObjectDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode(new EncodedImage($this->getTestResourceData())); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php deleted file mode 100644 index 9a76bd2f..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php +++ /dev/null @@ -1,56 +0,0 @@ -decoder = new FilePathImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - #[DataProvider('validFormatPathsProvider')] - public function testDecode(string $path, bool $result): void - { - if ($result === false) { - $this->expectException(DecoderException::class); - } - - $result = $this->decoder->decode($path); - - if ($result === true) { - $this->assertInstanceOf(Image::class, $result); - } - } - - public static function validFormatPathsProvider(): array - { - return [ - [self::getTestResourcePath('cats.gif'), true], - [self::getTestResourcePath('animation.gif'), true], - [self::getTestResourcePath('red.gif'), true], - [self::getTestResourcePath('green.gif'), true], - [self::getTestResourcePath('blue.gif'), true], - [self::getTestResourcePath('gradient.bmp'), true], - [self::getTestResourcePath('circle.png'), true], - ['no-path', false], - [str_repeat('x', PHP_MAXPATHLEN + 1), false], - ]; - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/FilePointerImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/FilePointerImageDecoderTest.php deleted file mode 100644 index e40777ef..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/FilePointerImageDecoderTest.php +++ /dev/null @@ -1,27 +0,0 @@ -setDriver(new Driver()); - - $fp = fopen($this->getTestResourcePath('test.jpg'), 'r'); - $result = $decoder->decode($fp); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/ImageObjectDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/ImageObjectDecoderTest.php deleted file mode 100644 index 2f8cbcd6..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/ImageObjectDecoderTest.php +++ /dev/null @@ -1,23 +0,0 @@ -decode($this->readTestImage('blue.gif')); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/NativeObjectDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/NativeObjectDecoderTest.php deleted file mode 100644 index 0b77f263..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/NativeObjectDecoderTest.php +++ /dev/null @@ -1,34 +0,0 @@ -decoder = new NativeObjectDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode( - imagecreatetruecolor(3, 2) - ); - - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/Decoders/SplFileInfoImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/SplFileInfoImageDecoderTest.php deleted file mode 100644 index d0a5617e..00000000 --- a/tests/Unit/Drivers/Gd/Decoders/SplFileInfoImageDecoderTest.php +++ /dev/null @@ -1,29 +0,0 @@ -setDriver(new Driver()); - - $result = $decoder->decode( - new SplFileInfo($this->getTestResourcePath('blue.gif')) - ); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Gd/DriverTest.php b/tests/Unit/Drivers/Gd/DriverTest.php deleted file mode 100644 index 3ba81e1e..00000000 --- a/tests/Unit/Drivers/Gd/DriverTest.php +++ /dev/null @@ -1,206 +0,0 @@ -driver = new Driver(); - } - - public function testId(): void - { - $this->assertEquals('GD', $this->driver->id()); - } - - public function testCreateImage(): void - { - $image = $this->driver->createImage(3, 2); - $this->assertInstanceOf(ImageInterface::class, $image); - $this->assertEquals(3, $image->width()); - $this->assertEquals(2, $image->height()); - } - - public function testCreateAnimation(): void - { - $image = $this->driver->createAnimation(function ($animation) { - $animation->add($this->getTestResourcePath('red.gif'), .25); - $animation->add($this->getTestResourcePath('green.gif'), .25); - })->setLoops(5); - $this->assertInstanceOf(ImageInterface::class, $image); - - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertEquals(5, $image->loops()); - $this->assertEquals(2, $image->count()); - } - - public function testHandleInputImage(): void - { - $result = $this->driver->handleInput($this->getTestResourcePath('test.jpg')); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testHandleInputColor(): void - { - $result = $this->driver->handleInput('ffffff'); - $this->assertInstanceOf(ColorInterface::class, $result); - } - - public function testHandleInputObjects(): void - { - $result = $this->driver->handleInput('ffffff', [ - new HexColorDecoder() - ]); - $this->assertInstanceOf(ColorInterface::class, $result); - } - - public function testHandleInputClassnames(): void - { - $result = $this->driver->handleInput('ffffff', [ - HexColorDecoder::class - ]); - $this->assertInstanceOf(ColorInterface::class, $result); - } - - public function testColorProcessor(): void - { - $result = $this->driver->colorProcessor(new Colorspace()); - $this->assertInstanceOf(ColorProcessorInterface::class, $result); - } - - #[DataProvider('supportsDataProvider')] - public function testSupports(bool $result, mixed $identifier): void - { - $this->assertEquals($result, $this->driver->supports($identifier)); - } - - public static function supportsDataProvider(): array - { - return [ - [true, Format::JPEG], - [true, MediaType::IMAGE_JPEG], - [true, MediaType::IMAGE_JPG], - [true, FileExtension::JPG], - [true, FileExtension::JPEG], - [true, 'jpg'], - [true, 'jpeg'], - [true, 'image/jpg'], - [true, 'image/jpeg'], - - [true, Format::WEBP], - [true, MediaType::IMAGE_WEBP], - [true, MediaType::IMAGE_X_WEBP], - [true, FileExtension::WEBP], - [true, 'webp'], - [true, 'image/webp'], - [true, 'image/x-webp'], - - [true, Format::GIF], - [true, MediaType::IMAGE_GIF], - [true, FileExtension::GIF], - [true, 'gif'], - [true, 'image/gif'], - - [true, Format::PNG], - [true, MediaType::IMAGE_PNG], - [true, MediaType::IMAGE_X_PNG], - [true, FileExtension::PNG], - [true, 'png'], - [true, 'image/png'], - [true, 'image/x-png'], - - [true, Format::AVIF], - [true, MediaType::IMAGE_AVIF], - [true, MediaType::IMAGE_X_AVIF], - [true, FileExtension::AVIF], - [true, 'avif'], - [true, 'image/avif'], - [true, 'image/x-avif'], - - [true, Format::BMP], - [true, FileExtension::BMP], - [true, MediaType::IMAGE_BMP], - [true, MediaType::IMAGE_MS_BMP], - [true, MediaType::IMAGE_X_BITMAP], - [true, MediaType::IMAGE_X_BMP], - [true, MediaType::IMAGE_X_MS_BMP], - [true, MediaType::IMAGE_X_WINDOWS_BMP], - [true, MediaType::IMAGE_X_WIN_BITMAP], - [true, MediaType::IMAGE_X_XBITMAP], - [true, 'bmp'], - [true, 'image/bmp'], - [true, 'image/ms-bmp'], - [true, 'image/x-bitmap'], - [true, 'image/x-bmp'], - [true, 'image/x-ms-bmp'], - [true, 'image/x-windows-bmp'], - [true, 'image/x-win-bitmap'], - [true, 'image/x-xbitmap'], - - [false, Format::TIFF], - [false, MediaType::IMAGE_TIFF], - [false, FileExtension::TIFF], - [false, FileExtension::TIF], - [false, 'tif'], - [false, 'tiff'], - [false, 'image/tiff'], - - [false, Format::JP2], - [false, MediaType::IMAGE_JP2], - [false, MediaType::IMAGE_JPX], - [false, MediaType::IMAGE_JPM], - [false, FileExtension::TIFF], - [false, FileExtension::TIF], - [false, FileExtension::JP2], - [false, FileExtension::J2K], - [false, FileExtension::JPF], - [false, FileExtension::JPM], - [false, FileExtension::JPG2], - [false, FileExtension::J2C], - [false, FileExtension::JPC], - [false, FileExtension::JPX], - [false, 'jp2'], - [false, 'j2k'], - [false, 'jpf'], - [false, 'jpm'], - [false, 'jpg2'], - [false, 'j2c'], - [false, 'jpc'], - [false, 'jpx'], - - [false, Format::HEIC], - [false, MediaType::IMAGE_HEIC], - [false, MediaType::IMAGE_HEIF], - [false, FileExtension::HEIC], - [false, FileExtension::HEIF], - [false, 'heic'], - [false, 'heif'], - [false, 'image/heic'], - [false, 'image/heif'], - - [false, 'tga'], - [false, 'image/tga'], - [false, 'image/x-targa'], - [false, 'foo'], - [false, ''], - ]; - } -} diff --git a/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php deleted file mode 100644 index 1419d54c..00000000 --- a/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new AvifEncoder(10); - $result = $encoder->encode($image); - $this->assertMediaType('image/avif', $result); - $this->assertEquals('image/avif', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php deleted file mode 100644 index 25a0d638..00000000 --- a/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new BmpEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], $result); - $this->assertEquals('image/bmp', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php deleted file mode 100644 index 6a87d7c5..00000000 --- a/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php +++ /dev/null @@ -1,53 +0,0 @@ -createTestAnimation(); - $encoder = new GifEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType('image/gif', $result); - $this->assertEquals('image/gif', $result->mimetype()); - $this->assertFalse( - Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() - ); - } - - public function testEncodeInterlaced(): void - { - $image = $this->createTestImage(3, 2); - $encoder = new GifEncoder(interlaced: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/gif', $result); - $this->assertEquals('image/gif', $result->mimetype()); - $this->assertTrue( - Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() - ); - } - - public function testEncodeInterlacedAnimation(): void - { - $image = $this->createTestAnimation(3, 2); - $encoder = new GifEncoder(interlaced: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/gif', $result); - $this->assertEquals('image/gif', $result->mimetype()); - $this->assertTrue( - Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() - ); - } -} diff --git a/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php deleted file mode 100644 index 5e29fcc8..00000000 --- a/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php +++ /dev/null @@ -1,38 +0,0 @@ -createTestImage(3, 2); - $encoder = new JpegEncoder(75); - $result = $encoder->encode($image); - $this->assertMediaType('image/jpeg', $result); - $this->assertEquals('image/jpeg', $result->mimetype()); - } - - public function testEncodeProgressive(): void - { - $image = $this->createTestImage(3, 2); - $encoder = new JpegEncoder(progressive: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/jpeg', $result); - $this->assertEquals('image/jpeg', $result->mimetype()); - $this->assertTrue($this->isProgressiveJpeg($result)); - } -} diff --git a/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php deleted file mode 100644 index fe5358cb..00000000 --- a/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php +++ /dev/null @@ -1,96 +0,0 @@ -createTestImage(3, 2); - $encoder = new PngEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType('image/png', $result); - $this->assertEquals('image/png', $result->mimetype()); - $this->assertFalse($this->isInterlacedPng($result)); - } - - public function testEncodeInterlaced(): void - { - $image = $this->createTestImage(3, 2); - $encoder = new PngEncoder(interlaced: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/png', $result); - $this->assertEquals('image/png', $result->mimetype()); - $this->assertTrue($this->isInterlacedPng($result)); - } - - #[DataProvider('indexedDataProvider')] - public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, string $result): void - { - $this->assertEquals( - $result, - $this->pngColorType($encoder->encode($image)), - ); - } - - public static function indexedDataProvider(): array - { - return [ - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('circle.png'), // truecolor-alpha - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('circle.png'), // indexedcolor-alpha - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: true), - 'indexed', - ], - ]; - } -} diff --git a/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php deleted file mode 100644 index c65a12fa..00000000 --- a/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new WebpEncoder(75); - $result = $encoder->encode($image); - $this->assertMediaType('image/webp', $result); - $this->assertEquals('image/webp', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Gd/FontProcessorTest.php b/tests/Unit/Drivers/Gd/FontProcessorTest.php deleted file mode 100644 index f098f10a..00000000 --- a/tests/Unit/Drivers/Gd/FontProcessorTest.php +++ /dev/null @@ -1,144 +0,0 @@ -boxSize('test', new Font()); - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertEquals(16, $size->width()); - $this->assertEquals(8, $size->height()); - } - - public function testBoxSizeGdTwo(): void - { - $processor = new FontProcessor(); - $size = $processor->boxSize('test', new Font('2')); - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertEquals(24, $size->width()); - $this->assertEquals(14, $size->height()); - } - - public function testBoxSizeGdThree(): void - { - $processor = new FontProcessor(); - $size = $processor->boxSize('test', new Font('3')); - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertEquals(28, $size->width()); - $this->assertEquals(14, $size->height()); - } - - public function testBoxSizeGdFour(): void - { - $processor = new FontProcessor(); - $size = $processor->boxSize('test', new Font('4')); - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertEquals(32, $size->width()); - $this->assertEquals(16, $size->height()); - } - - public function testBoxSizeGdFive(): void - { - $processor = new FontProcessor(); - $size = $processor->boxSize('test', new Font('5')); - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertEquals(36, $size->width()); - $this->assertEquals(16, $size->height()); - } - - public function testBoxSizeTtf(): void - { - $processor = new FontProcessor(); - $size = $processor->boxSize('ABC', $this->testFont()); - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertContains($size->width(), [74, 75, 76]); - $this->assertContains($size->height(), [19, 20, 21]); - } - - public function testNativeFontSize(): void - { - $processor = new FontProcessor(); - $size = $processor->nativeFontSize(new Font('5')); - $this->assertEquals(9.12, $size); - } - - public function testTextBlock(): void - { - $processor = new FontProcessor(); - $result = $processor->textBlock('test', new Font(), new Point(0, 0)); - $this->assertInstanceOf(TextBlock::class, $result); - } - - public function testTypographicalSize(): void - { - $processor = new FontProcessor(); - $result = $processor->typographicalSize(new Font()); - $this->assertEquals(8, $result); - } - - public function testCapHeight(): void - { - $processor = new FontProcessor(); - $result = $processor->capHeight(new Font()); - $this->assertEquals(8, $result); - } - - public function testLeading(): void - { - $processor = new FontProcessor(); - $result = $processor->leading(new Font()); - $this->assertEquals(8, $result); - } - - public function testNativeFontSizeTtf(): void - { - $processor = new FontProcessor(); - $size = $processor->nativeFontSize($this->testFont()); - $this->assertEquals(42.56, $size); - } - - public function testTextBlockTtf(): void - { - $processor = new FontProcessor(); - $result = $processor->textBlock('test', $this->testFont(), new Point(0, 0)); - $this->assertInstanceOf(TextBlock::class, $result); - } - - public function testTypographicalSizeTtf(): void - { - $processor = new FontProcessor(); - $result = $processor->typographicalSize($this->testFont()); - $this->assertContains($result, [44, 45]); - } - - public function testCapHeightTtf(): void - { - $processor = new FontProcessor(); - $result = $processor->capHeight($this->testFont()); - $this->assertContains($result, [44, 45]); - } - - public function testLeadingTtf(): void - { - $processor = new FontProcessor(); - $result = $processor->leading($this->testFont()); - $this->assertContains($result, [44, 45]); - } - - private function testFont(): Font - { - return (new Font($this->getTestResourcePath('test.ttf')))->setSize(56); - } -} diff --git a/tests/Unit/Drivers/Gd/FrameTest.php b/tests/Unit/Drivers/Gd/FrameTest.php deleted file mode 100644 index f7a33169..00000000 --- a/tests/Unit/Drivers/Gd/FrameTest.php +++ /dev/null @@ -1,111 +0,0 @@ -getTestFrame(); - $this->assertInstanceOf(Frame::class, $frame); - } - - public function testGetNative(): void - { - $frame = $this->getTestFrame(); - $this->assertInstanceOf(GdImage::class, $frame->native()); - } - - public function testSetCore(): void - { - $core1 = imagecreatetruecolor(3, 2); - $core2 = imagecreatetruecolor(3, 3); - $frame = new Frame($core1); - $this->assertEquals(2, $frame->size()->height()); - $result = $frame->setNative($core2); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(3, $frame->size()->height()); - } - - public function testGetSize(): void - { - $frame = $this->getTestFrame(); - $this->assertInstanceOf(Rectangle::class, $frame->size()); - } - - public function testSetGetDelay(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(0, $frame->delay()); - - $result = $frame->setDelay(1.5); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(1.5, $frame->delay()); - } - - public function testSetGetDispose(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(1, $frame->dispose()); - - $result = $frame->setDispose(100); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->dispose()); - } - - public function testSetGetOffsetLeft(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(0, $frame->offsetLeft()); - - $result = $frame->setOffsetLeft(100); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->offsetLeft()); - } - - public function testSetGetOffsetTop(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(0, $frame->offsetTop()); - - $result = $frame->setOffsetTop(100); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->offsetTop()); - } - - public function testSetGetOffset(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(0, $frame->offsetTop()); - $this->assertEquals(0, $frame->offsetLeft()); - - $result = $frame->setOffset(100, 200); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->offsetLeft()); - $this->assertEquals(200, $frame->offsetTop()); - } - - public function testToImage(): void - { - $frame = $this->getTestFrame(); - $this->assertInstanceOf(Image::class, $frame->toImage(new Driver())); - } -} diff --git a/tests/Unit/Drivers/Gd/ImageTest.php b/tests/Unit/Drivers/Gd/ImageTest.php deleted file mode 100644 index 83c76283..00000000 --- a/tests/Unit/Drivers/Gd/ImageTest.php +++ /dev/null @@ -1,389 +0,0 @@ -image = new Image( - new Driver(), - new Core([ - new Frame(imagecreatetruecolor(3, 2)), - new Frame(imagecreatetruecolor(3, 2)), - ]), - new Collection([ - 'test' => 'foo' - ]), - ); - } - - public function testClone(): void - { - $image = $this->readTestImage('gradient.gif'); - $clone = clone $image; - - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $clone->width()); - $result = $clone->crop(4, 4); - $this->assertEquals(16, $image->width()); - $this->assertEquals(4, $clone->width()); - $this->assertEquals(4, $result->width()); - - $this->assertEquals('ff0000', $image->pickColor(0, 0)->toHex()); - $this->assertTransparency($image->pickColor(1, 0)); - - $this->assertEquals('ff0000', $clone->pickColor(0, 0)->toHex()); - $this->assertTransparency($image->pickColor(1, 0)); - } - - public function testDriver(): void - { - $this->assertInstanceOf(Driver::class, $this->image->driver()); - } - - public function testCore(): void - { - $this->assertInstanceOf(Core::class, $this->image->core()); - } - - public function testCount(): void - { - $this->assertEquals(2, $this->image->count()); - } - - public function testIteration(): void - { - foreach ($this->image as $frame) { - $this->assertInstanceOf(Frame::class, $frame); - } - } - - public function testIsAnimated(): void - { - $this->assertTrue($this->image->isAnimated()); - } - - public function testSetGetLoops(): void - { - $this->assertEquals(0, $this->image->loops()); - $result = $this->image->setLoops(10); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals(10, $this->image->loops()); - } - - public function testRemoveAnimation(): void - { - $this->assertTrue($this->image->isAnimated()); - $result = $this->image->removeAnimation(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertFalse($this->image->isAnimated()); - } - - public function testSliceAnimation(): void - { - $this->assertEquals(2, $this->image->count()); - $result = $this->image->sliceAnimation(0, 1); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals(1, $this->image->count()); - } - - public function testExif(): void - { - $this->assertInstanceOf(Collection::class, $this->image->exif()); - $this->assertEquals('foo', $this->image->exif('test')); - } - - public function testModify(): void - { - $result = $this->image->modify(new GreyscaleModifier()); - $this->assertInstanceOf(Image::class, $result); - } - - public function testAnalyze(): void - { - $result = $this->image->analyze(new WidthAnalyzer()); - $this->assertEquals(3, $result); - } - - public function testEncode(): void - { - $result = $this->image->encode(new PngEncoder()); - $this->assertInstanceOf(EncodedImage::class, $result); - } - - public function testAutoEncode(): void - { - $result = $this->readTestImage('blue.gif')->encode(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - } - - public function testEncodeByMediaType(): void - { - $result = $this->readTestImage('blue.gif')->encodeByMediaType(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - - $result = $this->readTestImage('blue.gif')->encodeByMediaType('image/png'); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - - $result = $this->readTestImage('blue.gif')->encodeByMediaType(MediaType::IMAGE_PNG); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - } - - public function testEncodeByExtension(): void - { - $result = $this->readTestImage('blue.gif')->encodeByExtension(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - - $result = $this->readTestImage('blue.gif')->encodeByExtension('png'); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - - $result = $this->readTestImage('blue.gif')->encodeByExtension(FileExtension::PNG); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - } - - public function testEncodeByPath(): void - { - $result = $this->readTestImage('blue.gif')->encodeByPath(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - - $result = $this->readTestImage('blue.gif')->encodeByPath('foo/bar.png'); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - } - - public function testSaveAsFormat(): void - { - $path = __DIR__ . '/tmp.png'; - $result = $this->readTestImage('blue.gif')->save($path); - $this->assertInstanceOf(Image::class, $result); - $this->assertFileExists($path); - $this->assertMediaType('image/png', file_get_contents($path)); - unlink($path); - } - - public function testSaveFallback(): void - { - $path = __DIR__ . '/tmp.unknown'; - $result = $this->readTestImage('blue.gif')->save($path); - $this->assertInstanceOf(Image::class, $result); - $this->assertFileExists($path); - $this->assertMediaType('image/gif', file_get_contents($path)); - unlink($path); - } - - public function testSaveUndeterminedPath(): void - { - $this->expectException(EncoderException::class); - $this->createTestImage(2, 3)->save(); - } - - public function testWidthHeightSize(): void - { - $this->assertEquals(3, $this->image->width()); - $this->assertEquals(2, $this->image->height()); - $this->assertInstanceOf(SizeInterface::class, $this->image->size()); - } - - public function testColorspace(): void - { - $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); - } - - public function testSetColorspace(): void - { - $this->expectException(NotSupportedException::class); - $this->image->setColorspace(Colorspace::class); - } - - public function testSetGetResolution(): void - { - $resolution = $this->image->resolution(); - $this->assertInstanceOf(ResolutionInterface::class, $resolution); - $this->assertEquals(96, $resolution->x()); - $this->assertEquals(96, $resolution->y()); - $result = $this->image->setResolution(300, 300); - $resolution = $this->image->resolution(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals(300, $resolution->x()); - $this->assertEquals(300, $resolution->y()); - } - - public function testPickColor(): void - { - $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0)); - $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0, 1)); - } - - public function testPickColors(): void - { - $result = $this->image->pickColors(0, 0); - $this->assertInstanceOf(Collection::class, $result); - $this->assertEquals(2, $result->count()); - } - - public function testProfile(): void - { - $this->expectException(NotSupportedException::class); - $this->image->profile(); - } - - public function testReduceColors(): void - { - $image = $this->readTestImage(); - $result = $image->reduceColors(8); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testSharpen(): void - { - $this->assertInstanceOf(Image::class, $this->image->sharpen(12)); - } - - public function testText(): void - { - $this->assertInstanceOf(Image::class, $this->image->text('test', 0, 0, new Font())); - } - - public function testBlendTransparencyDefault(): void - { - $image = $this->readTestImage('gradient.gif'); - $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); - $result = $image->blendTransparency(); - $this->assertColor(255, 255, 255, 255, $image->pickColor(1, 0)); - $this->assertColor(255, 255, 255, 255, $result->pickColor(1, 0)); - } - - public function testBlendTransparencyArgument(): void - { - $image = $this->readTestImage('gradient.gif'); - $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); - $result = $image->blendTransparency('ff5500'); - $this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0)); - $this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0)); - } - - public function testToJpeg(): void - { - $this->assertMediaType('image/jpeg', $this->image->toJpeg()); - $this->assertMediaType('image/jpeg', $this->image->toJpg()); - } - - public function testToJpeg2000(): void - { - $this->expectException(NotSupportedException::class); - $this->image->toJpeg2000(); - } - - public function testToPng(): void - { - $this->assertMediaType('image/png', $this->image->toPng()); - } - - public function testToGif(): void - { - $this->assertMediaType('image/gif', $this->image->toGif()); - } - - public function testToWebp(): void - { - $this->assertMediaType('image/webp', $this->image->toWebp()); - } - - public function testToBitmap(): void - { - $this->assertMediaTypeBitmap($this->image->toBitmap()); - $this->assertMediaTypeBitmap($this->image->toBmp()); - } - - public function testToAvif(): void - { - $this->assertMediaType('image/avif', $this->image->toAvif()); - } - - public function testToTiff(): void - { - $this->expectException(NotSupportedException::class); - $this->image->toTiff(); - } - - public function testToHeic(): void - { - $this->expectException(NotSupportedException::class); - $this->image->toHeic(); - } - - public function testInvert(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); - $result = $image->invert(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); - } - - public function testPixelate(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $result = $image->pixelate(10); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('6aaa8b', $image->pickColor(14, 14)->toHex()); - } - - public function testGreyscale(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); - $result = $image->greyscale(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); - } - - public function testBrightness(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $result = $image->brightness(30); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals('4cfaff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/BlurModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/BlurModifierTest.php deleted file mode 100644 index 2e5fcaa7..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/BlurModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new BlurModifier(30)); - $this->assertEquals('4fa68d', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/BrightnessModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/BrightnessModifierTest.php deleted file mode 100644 index 73c34688..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/BrightnessModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new BrightnessModifier(30)); - $this->assertEquals('4cfaff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ColorizeModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ColorizeModifierTest.php deleted file mode 100644 index 0876ccc6..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ColorizeModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('tile.png'); - $image = $image->modify(new ColorizeModifier(100, -100, -100)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(15, 15)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ContainModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ContainModifierTest.php deleted file mode 100644 index 35138fe7..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ContainModifierTest.php +++ /dev/null @@ -1,29 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new ContainModifier(200, 100, 'ff0')); - $this->assertEquals(200, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertTransparency($image->pickColor(140, 10)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(175, 10)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ContrastModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ContrastModifierTest.php deleted file mode 100644 index f1c1cbae..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ContrastModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new ContrastModifier(30)); - $this->assertEquals('00ceff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/CoverDownModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/CoverDownModifierTest.php deleted file mode 100644 index 4b08306a..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/CoverDownModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new CoverDownModifier(100, 100, 'center')); - $this->assertEquals(100, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); - $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); - $this->assertTransparency($image->pickColor(90, 30)); - } - - public function testModifyOddSize(): void - { - $image = $this->createTestImage(375, 250); - $image->modify(new CoverDownModifier(240, 90, 'center')); - $this->assertEquals(240, $image->width()); - $this->assertEquals(90, $image->height()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php deleted file mode 100644 index 83c9487b..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/CoverModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new CoverModifier(100, 100, 'center')); - $this->assertEquals(100, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); - $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); - $this->assertTransparency($image->pickColor(90, 30)); - } - - public function testModifyOddSize(): void - { - $image = $this->createTestImage(375, 250); - $image->modify(new CoverModifier(240, 90, 'center')); - $this->assertEquals(240, $image->width()); - $this->assertEquals(90, $image->height()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/CropModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/CropModifierTest.php deleted file mode 100644 index 4a5e268d..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/CropModifierTest.php +++ /dev/null @@ -1,39 +0,0 @@ -readTestImage('blocks.png'); - $image = $image->modify(new CropModifier(200, 200, 0, 0, 'ffffff', 'bottom-right')); - $this->assertEquals(200, $image->width()); - $this->assertEquals(200, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(100, 100)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(190, 190)); - } - - public function testModifyExtend(): void - { - $image = $this->readTestImage('blocks.png'); - $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000', 'top-left')); - $this->assertEquals(800, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(9, 9)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(16, 16)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(445, 16)); - $this->assertTransparency($image->pickColor(460, 16)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/DrawBezierModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/DrawBezierModifierTest.php deleted file mode 100644 index 26414fd3..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/DrawBezierModifierTest.php +++ /dev/null @@ -1,33 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $drawable = new Bezier([ - new Point(0, 0), - new Point(15, 0), - new Point(15, 15), - new Point(0, 15) - ]); - $drawable->setBackgroundColor('b53717'); - $image->modify(new DrawBezierModifier($drawable)); - $this->assertEquals('b53717', $image->pickColor(5, 5)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/DrawEllipseModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/DrawEllipseModifierTest.php deleted file mode 100644 index da79e1e7..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/DrawEllipseModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $drawable = new Ellipse(10, 10, new Point(14, 14)); - $drawable->setBackgroundColor('b53717'); - $image->modify(new DrawEllipseModifier($drawable)); - $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/DrawLineModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/DrawLineModifierTest.php deleted file mode 100644 index 67e19f11..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/DrawLineModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $line = new Line(new Point(0, 0), new Point(10, 0), 4); - $line->setBackgroundColor('b53517'); - $image->modify(new DrawLineModifier($line)); - $this->assertEquals('b53517', $image->pickColor(0, 0)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/DrawPixelModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/DrawPixelModifierTest.php deleted file mode 100644 index c72f22f4..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/DrawPixelModifierTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new DrawPixelModifier(new Point(14, 14), 'ffffff')); - $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/DrawPolygonModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/DrawPolygonModifierTest.php deleted file mode 100644 index e966b060..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/DrawPolygonModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $drawable = new Polygon([new Point(0, 0), new Point(15, 15), new Point(20, 20)]); - $drawable->setBackgroundColor('b53717'); - $image->modify(new DrawPolygonModifier($drawable)); - $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/DrawRectangleModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/DrawRectangleModifierTest.php deleted file mode 100644 index c7ef3411..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/DrawRectangleModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $rectangle = new Rectangle(300, 200, new Point(14, 14)); - $rectangle->setBackgroundColor('ffffff'); - $image->modify(new DrawRectangleModifier($rectangle)); - $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/FillModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/FillModifierTest.php deleted file mode 100644 index d0ef84e0..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/FillModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); - $image->modify(new FillModifier(new Color(204, 204, 204), new Point(540, 400))); - $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); - } - - public function testFillAllColor(): void - { - $image = $this->readTestImage('blocks.png'); - $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); - $image->modify(new FillModifier(new Color(204, 204, 204))); - $this->assertEquals('cccccc', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/FlipFlopModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/FlipFlopModifierTest.php deleted file mode 100644 index a5fd7bef..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/FlipFlopModifierTest.php +++ /dev/null @@ -1,33 +0,0 @@ -readTestImage('tile.png'); - $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); - $image->modify(new FlipModifier()); - $this->assertTransparency($image->pickColor(0, 0)); - } - - public function testFlopImage(): void - { - $image = $this->readTestImage('tile.png'); - $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); - $image->modify(new FlopModifier()); - $this->assertTransparency($image->pickColor(0, 0)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/GammaModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/GammaModifierTest.php deleted file mode 100644 index b193d829..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/GammaModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $image->modify(new GammaModifier(2.1)); - $this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/GreyscaleModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/GreyscaleModifierTest.php deleted file mode 100644 index 7dad56ee..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/GreyscaleModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); - $image->modify(new GreyscaleModifier()); - $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/InvertModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/InvertModifierTest.php deleted file mode 100644 index 99c8087a..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/InvertModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); - $image->modify(new InvertModifier()); - $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/PixelateModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/PixelateModifierTest.php deleted file mode 100644 index 444b95fc..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/PixelateModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new PixelateModifier(10)); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('6aaa8b', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/PlaceModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/PlaceModifierTest.php deleted file mode 100644 index ad8195be..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/PlaceModifierTest.php +++ /dev/null @@ -1,42 +0,0 @@ -readTestImage('test.jpg'); - $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); - $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0)); - $this->assertEquals('32250d', $image->pickColor(300, 25)->toHex()); - } - - public function testColorChangeOpacityPng(): void - { - $image = $this->readTestImage('test.jpg'); - $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); - $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0, 50)); - $this->assertColor(152, 112, 40, 255, $image->pickColor(300, 25), tolerance: 1); - $this->assertColor(255, 202, 107, 255, $image->pickColor(274, 5), tolerance: 1); - } - - public function testColorChangeOpacityJpeg(): void - { - $image = $this->createTestImage(16, 16)->fill('0000ff'); - $this->assertEquals('0000ff', $image->pickColor(10, 10)->toHex()); - $image->modify(new PlaceModifier($this->getTestResourcePath('exif.jpg'), opacity: 50)); - $this->assertColor(127, 83, 127, 255, $image->pickColor(10, 10), tolerance: 1); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php deleted file mode 100644 index 73d253fc..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/QuantizeColorsModifierTest.php +++ /dev/null @@ -1,58 +0,0 @@ -readTestImage('gradient.bmp'); - $this->assertColorCount(15, $image); - $image->modify(new QuantizeColorsModifier(4)); - $this->assertColorCount(4, $image); - } - - public function testNoColorReduction(): void - { - $image = $this->readTestImage('gradient.bmp'); - $this->assertColorCount(15, $image); - $image->modify(new QuantizeColorsModifier(150)); - $this->assertColorCount(15, $image); - } - - public function testInvalidColorInput(): void - { - $image = $this->readTestImage('gradient.bmp'); - $this->expectException(InputException::class); - $image->modify(new QuantizeColorsModifier(0)); - } - - private function assertColorCount(int $count, ImageInterface $image): void - { - $colors = []; - $width = $image->width(); - $height = $image->height(); - for ($x = 0; $x < $width; $x++) { - for ($y = 0; $y < $height; $y++) { - $rgb = imagecolorat($image->core()->native(), $x, $y); - $color = imagecolorsforindex($image->core()->native(), $rgb); - $color = implode('-', $color); - $colors[$color] = $color; - } - } - - $this->assertEquals(count($colors), $count); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/RemoveAnimationModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/RemoveAnimationModifierTest.php deleted file mode 100644 index 43cdce8d..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/RemoveAnimationModifierTest.php +++ /dev/null @@ -1,42 +0,0 @@ -readTestImage('animation.gif'); - $this->assertEquals(8, count($image)); - $result = $image->modify(new RemoveAnimationModifier(2)); - $this->assertEquals(1, count($image)); - $this->assertEquals(1, count($result)); - } - - public function testApplyPercent(): void - { - $image = $this->readTestImage('animation.gif'); - $this->assertEquals(8, count($image)); - $result = $image->modify(new RemoveAnimationModifier('20%')); - $this->assertEquals(1, count($image)); - $this->assertEquals(1, count($result)); - } - - public function testApplyInvalid(): void - { - $image = $this->readTestImage('animation.gif'); - $this->expectException(InputException::class); - $image->modify(new RemoveAnimationModifier('test')); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php deleted file mode 100644 index 04a2d886..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php +++ /dev/null @@ -1,55 +0,0 @@ -createTestImage(1, 1); - $this->assertEquals(1, $image->width()); - $this->assertEquals(1, $image->height()); - $image->modify(new ResizeCanvasModifier(3, 3, 'ff0', 'center')); - $this->assertEquals(3, $image->width()); - $this->assertEquals(3, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); - } - - public function testModifyWithTransparency(): void - { - $image = $this->readTestImage('tile.png'); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $image->modify(new ResizeCanvasModifier(18, 18, 'ff0', 'center')); - $this->assertEquals(18, $image->width()); - $this->assertEquals(18, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); - $this->assertTransparency($image->pickColor(12, 1)); - } - - public function testModifyEdge(): void - { - $image = $this->createTestImage(1, 1); - $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); - $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom')); - $this->assertEquals(1, $image->width()); - $this->assertEquals(2, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 1)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifierTest.php deleted file mode 100644 index 2752bbf6..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ResizeCanvasRelativeModifierTest.php +++ /dev/null @@ -1,44 +0,0 @@ -createTestImage(1, 1); - $this->assertEquals(1, $image->width()); - $this->assertEquals(1, $image->height()); - $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); - $this->assertEquals(3, $image->width()); - $this->assertEquals(3, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); - } - - public function testModifyWithTransparency(): void - { - $image = $this->readTestImage('tile.png'); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); - $this->assertEquals(18, $image->width()); - $this->assertEquals(18, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); - $this->assertTransparency($image->pickColor(12, 1)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ResizeModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ResizeModifierTest.php deleted file mode 100644 index dde9c0d2..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ResizeModifierTest.php +++ /dev/null @@ -1,30 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new ResizeModifier(200, 100)); - $this->assertEquals(200, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(150, 70)); - $this->assertColor(0, 255, 0, 255, $image->pickColor(125, 70)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(130, 54)); - $this->assertTransparency($image->pickColor(170, 30)); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/ResolutionModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/ResolutionModifierTest.php deleted file mode 100644 index df237fd4..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/ResolutionModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('test.jpg'); - $this->assertEquals(72.0, $image->resolution()->x()); - $this->assertEquals(72.0, $image->resolution()->y()); - $image->modify(new ResolutionModifier(1, 2)); - $this->assertEquals(1.0, $image->resolution()->x()); - $this->assertEquals(2.0, $image->resolution()->y()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/RotateModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/RotateModifierTest.php deleted file mode 100644 index f7214a7e..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/RotateModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('test.jpg'); - $this->assertEquals(320, $image->width()); - $this->assertEquals(240, $image->height()); - $image->modify(new RotateModifier(90, 'fff')); - $this->assertEquals(240, $image->width()); - $this->assertEquals(320, $image->height()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/SharpenModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/SharpenModifierTest.php deleted file mode 100644 index 7b309fa5..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/SharpenModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('60ab96', $image->pickColor(15, 14)->toHex()); - $image->modify(new SharpenModifier(10)); - $this->assertEquals('4daba7', $image->pickColor(15, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/TextModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/TextModifierTest.php deleted file mode 100644 index 3bd1f503..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/TextModifierTest.php +++ /dev/null @@ -1,37 +0,0 @@ -setColor('ff0055'); - - $modifier = new class ('test', new Point(), $font) extends TextModifier - { - public function test() - { - return $this->textColor(); - } - }; - - $modifier->setDriver(new Driver()); - - $this->assertInstanceOf(ColorInterface::class, $modifier->test()); - } -} diff --git a/tests/Unit/Drivers/Gd/Modifiers/TrimModifierTest.php b/tests/Unit/Drivers/Gd/Modifiers/TrimModifierTest.php deleted file mode 100644 index c85c8c88..00000000 --- a/tests/Unit/Drivers/Gd/Modifiers/TrimModifierTest.php +++ /dev/null @@ -1,55 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals(50, $image->width()); - $this->assertEquals(50, $image->height()); - $image->modify(new TrimModifier()); - $this->assertEquals(28, $image->width()); - $this->assertEquals(28, $image->height()); - } - - public function testTrimGradient(): void - { - $image = $this->readTestImage('radial.png'); - $this->assertEquals(50, $image->width()); - $this->assertEquals(50, $image->height()); - $image->modify(new TrimModifier(50)); - $this->assertEquals(35, $image->width()); - $this->assertEquals(35, $image->height()); - } - - public function testTrimHighTolerance(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals(50, $image->width()); - $this->assertEquals(50, $image->height()); - $image->modify(new TrimModifier(1000000)); - $this->assertEquals(1, $image->width()); - $this->assertEquals(1, $image->height()); - $this->assertColor(255, 255, 255, 0, $image->pickColor(0, 0)); - } - - public function testTrimAnimated(): void - { - $image = $this->readTestImage('animation.gif'); - $this->expectException(NotSupportedException::class); - $image->modify(new TrimModifier()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php deleted file mode 100644 index ba90b8b4..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/ColorspaceAnalyzerTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new ColorspaceAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(ColorspaceInterface::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php deleted file mode 100644 index ab1e3125..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/HeightAnalyzerTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new HeightAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertEquals(16, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php deleted file mode 100644 index 0a577629..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/PixelColorAnalyzerTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new PixelColorAnalyzer(0, 0); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(ColorInterface::class, $result); - $this->assertEquals('b4e000', $result->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/PixelColorsAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/PixelColorsAnalyzerTest.php deleted file mode 100644 index c1651bef..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/PixelColorsAnalyzerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new PixelColorsAnalyzer(0, 0); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(Collection::class, $result); - $this->assertInstanceOf(ColorInterface::class, $result->first()); - $this->assertEquals('b4e000', $result->first()->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php deleted file mode 100644 index f68e87a8..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/ProfileAnalyzerTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new ProfileAnalyzer(); - $this->expectException(ColorException::class); - $analyzer->analyze($image); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php deleted file mode 100644 index 363fbbdb..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/ResolutionAnalyzerTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new ResolutionAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertInstanceOf(Resolution::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php b/tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php deleted file mode 100644 index acfecf53..00000000 --- a/tests/Unit/Drivers/Imagick/Analyzers/WidthAnalyzerTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('tile.png'); - $analyzer = new WidthAnalyzer(); - $result = $analyzer->analyze($image); - $this->assertEquals(16, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/ColorProcessorTest.php b/tests/Unit/Drivers/Imagick/ColorProcessorTest.php deleted file mode 100644 index 55164ae9..00000000 --- a/tests/Unit/Drivers/Imagick/ColorProcessorTest.php +++ /dev/null @@ -1,27 +0,0 @@ -colorToNative(new Color(255, 55, 0, 255)); - $this->assertInstanceOf(ImagickPixel::class, $result); - } - - public function testNativeToColor(): void - { - $processor = new ColorProcessor(new Colorspace()); - $processor->nativeToColor(new ImagickPixel('rgb(255, 55, 0)')); - } -} diff --git a/tests/Unit/Drivers/Imagick/CoreTest.php b/tests/Unit/Drivers/Imagick/CoreTest.php deleted file mode 100644 index 1a6fa89a..00000000 --- a/tests/Unit/Drivers/Imagick/CoreTest.php +++ /dev/null @@ -1,146 +0,0 @@ -newImage(10, 10, new ImagickPixel('red')); - $imagick->addImage($im); - - $im = new Imagick(); - $im->newImage(10, 10, new ImagickPixel('green')); - $imagick->addImage($im); - - $im = new Imagick(); - $im->newImage(10, 10, new ImagickPixel('blue')); - $imagick->addImage($im); - - $this->core = new Core($imagick); - } - - public function testAdd(): void - { - $imagick = new Imagick(); - $imagick->newImage(100, 100, new ImagickPixel('red')); - $this->assertEquals(3, $this->core->count()); - $result = $this->core->add(new Frame($imagick)); - $this->assertEquals(4, $this->core->count()); - $this->assertInstanceOf(Core::class, $result); - } - - public function testCount(): void - { - $this->assertEquals(3, $this->core->count()); - } - - public function testIterator(): void - { - foreach ($this->core as $frame) { - $this->assertInstanceOf(Frame::class, $frame); - } - } - - public function testNative(): void - { - $this->assertInstanceOf(Imagick::class, $this->core->native()); - } - - public function testSetNative(): void - { - $imagick1 = new Imagick(); - $imagick1->newImage(10, 10, new ImagickPixel('red')); - - $imagick2 = new Imagick(); - $imagick2->newImage(10, 10, new ImagickPixel('red')); - - $core = new Core($imagick1); - $this->assertEquals($imagick1, $core->native()); - $core->setNative($imagick2); - $this->assertEquals($imagick2, $core->native()); - } - - public function testFrame(): void - { - $this->assertInstanceOf(Frame::class, $this->core->frame(0)); - $this->assertInstanceOf(Frame::class, $this->core->frame(1)); - $this->assertInstanceOf(Frame::class, $this->core->frame(2)); - $this->expectException(AnimationException::class); - $this->core->frame(3); - } - - public function testSetGetLoops(): void - { - $this->assertEquals(0, $this->core->loops()); - $result = $this->core->setLoops(12); - $this->assertEquals(12, $this->core->loops()); - $this->assertInstanceOf(Core::class, $result); - } - - public function testHas(): void - { - $this->assertTrue($this->core->has(0)); - $this->assertTrue($this->core->has(1)); - $this->assertTrue($this->core->has(2)); - $this->assertFalse($this->core->has(3)); - } - - public function testPush(): void - { - $im = new Imagick(); - $im->newImage(100, 100, new ImagickPixel('green')); - $this->assertEquals(3, $this->core->count()); - $result = $this->core->push(new Frame($im)); - $this->assertEquals(4, $this->core->count()); - $this->assertEquals(4, $result->count()); - } - - public function testGet(): void - { - $this->assertInstanceOf(Frame::class, $this->core->get(0)); - $this->assertInstanceOf(Frame::class, $this->core->get(1)); - $this->assertInstanceOf(Frame::class, $this->core->get(2)); - $this->assertNull($this->core->get(3)); - $this->assertEquals('foo', $this->core->get(3, 'foo')); - } - - public function testEmpty(): void - { - $result = $this->core->empty(); - $this->assertEquals(0, $this->core->count()); - $this->assertEquals(0, $result->count()); - } - - public function testSlice(): void - { - $this->assertEquals(3, $this->core->count()); - $result = $this->core->slice(1, 2); - $this->assertEquals(2, $this->core->count()); - $this->assertEquals(2, $result->count()); - } - - public function testFirst(): void - { - $this->assertInstanceOf(Frame::class, $this->core->first()); - } - - public function testLast(): void - { - $this->assertInstanceOf(Frame::class, $this->core->last()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/Base64ImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/Base64ImageDecoderTest.php deleted file mode 100644 index d4f622eb..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/Base64ImageDecoderTest.php +++ /dev/null @@ -1,41 +0,0 @@ -decoder = new Base64ImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode( - base64_encode($this->getTestResourceData('blue.gif')) - ); - - $this->assertInstanceOf(Image::class, $result); - } - - public function testDecoderInvalid(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode('test'); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php deleted file mode 100644 index 2b221166..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php +++ /dev/null @@ -1,76 +0,0 @@ -decoder = new BinaryImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecodePng(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('tile.png'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertInstanceOf(RgbColorspace::class, $image->colorspace()); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertCount(1, $image); - } - - public function testDecodeGif(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('red.gif'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertCount(1, $image); - } - - public function testDecodeAnimatedGif(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('cats.gif'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(75, $image->width()); - $this->assertEquals(50, $image->height()); - $this->assertCount(4, $image); - } - - public function testDecodeJpegWithExif(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('exif.jpg'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertCount(1, $image); - $this->assertEquals('Oliver Vogel', $image->exif('IFD0.Artist')); - } - - public function testDecodeCmykImage(): void - { - $image = $this->decoder->decode(file_get_contents($this->getTestResourcePath('cmyk.jpg'))); - $this->assertInstanceOf(Image::class, $image); - $this->assertInstanceOf(CmykColorspace::class, $image->colorspace()); - } - - public function testDecodeNonString(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode(new stdClass()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/DataUriImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/DataUriImageDecoderTest.php deleted file mode 100644 index db8de4d5..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/DataUriImageDecoderTest.php +++ /dev/null @@ -1,54 +0,0 @@ -decoder = new DataUriImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode( - sprintf('data:image/jpeg;base64,%s', base64_encode($this->getTestResourceData('blue.gif'))) - ); - - $this->assertInstanceOf(Image::class, $result); - } - - public function testDecoderNonString(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode(new stdClass()); - } - - public function testDecoderInvalid(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode('invalid'); - } - - public function testDecoderNonImage(): void - { - $this->expectException(DecoderException::class); - $this->decoder->decode('data:text/plain;charset=utf-8,test'); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php deleted file mode 100644 index 826498d3..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/EncodedImageObjectDecoderTest.php +++ /dev/null @@ -1,32 +0,0 @@ -decoder = new EncodedImageObjectDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $result = $this->decoder->decode(new EncodedImage($this->getTestResourceData())); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php deleted file mode 100644 index 8e5cd768..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php +++ /dev/null @@ -1,56 +0,0 @@ -decoder = new FilePathImageDecoder(); - $this->decoder->setDriver(new Driver()); - } - - #[DataProvider('validFormatPathsProvider')] - public function testDecode(string $path, bool $result): void - { - if ($result === false) { - $this->expectException(DecoderException::class); - } - - $result = $this->decoder->decode($path); - - if ($result === true) { - $this->assertInstanceOf(Image::class, $result); - } - } - - public static function validFormatPathsProvider(): array - { - return [ - [self::getTestResourcePath('cats.gif'), true], - [self::getTestResourcePath('animation.gif'), true], - [self::getTestResourcePath('red.gif'), true], - [self::getTestResourcePath('green.gif'), true], - [self::getTestResourcePath('blue.gif'), true], - [self::getTestResourcePath('gradient.bmp'), true], - [self::getTestResourcePath('circle.png'), true], - ['no-path', false], - [str_repeat('x', PHP_MAXPATHLEN + 1), false], - ]; - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/FilePointerImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/FilePointerImageDecoderTest.php deleted file mode 100644 index 15724014..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/FilePointerImageDecoderTest.php +++ /dev/null @@ -1,26 +0,0 @@ -setDriver(new Driver()); - $fp = fopen($this->getTestResourcePath('test.jpg'), 'r'); - $result = $decoder->decode($fp); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/ImageObjectDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/ImageObjectDecoderTest.php deleted file mode 100644 index 70efd2b3..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/ImageObjectDecoderTest.php +++ /dev/null @@ -1,23 +0,0 @@ -decode($this->readTestImage('blue.gif')); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/NativeObjectDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/NativeObjectDecoderTest.php deleted file mode 100644 index e397c36e..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/NativeObjectDecoderTest.php +++ /dev/null @@ -1,36 +0,0 @@ -decoder = new NativeObjectDecoder(); - $this->decoder->setDriver(new Driver()); - } - - public function testDecode(): void - { - $native = new Imagick(); - $native->newImage(3, 2, new ImagickPixel('red'), 'png'); - $result = $this->decoder->decode($native); - - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/Decoders/SplFileInfoImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/SplFileInfoImageDecoderTest.php deleted file mode 100644 index c4c26c86..00000000 --- a/tests/Unit/Drivers/Imagick/Decoders/SplFileInfoImageDecoderTest.php +++ /dev/null @@ -1,28 +0,0 @@ -setDriver(new Driver()); - $result = $decoder->decode( - new SplFileInfo($this->getTestResourcePath('blue.gif')) - ); - $this->assertInstanceOf(Image::class, $result); - } -} diff --git a/tests/Unit/Drivers/Imagick/DriverTest.php b/tests/Unit/Drivers/Imagick/DriverTest.php deleted file mode 100644 index 93bfd7ae..00000000 --- a/tests/Unit/Drivers/Imagick/DriverTest.php +++ /dev/null @@ -1,206 +0,0 @@ -driver = new Driver(); - } - - public function testId(): void - { - $this->assertEquals('Imagick', $this->driver->id()); - } - - public function testCreateImage(): void - { - $image = $this->driver->createImage(3, 2); - $this->assertInstanceOf(ImageInterface::class, $image); - $this->assertEquals(3, $image->width()); - $this->assertEquals(2, $image->height()); - } - - public function testCreateAnimation(): void - { - $image = $this->driver->createAnimation(function ($animation) { - $animation->add($this->getTestResourcePath('red.gif'), .25); - $animation->add($this->getTestResourcePath('green.gif'), .25); - })->setLoops(5); - $this->assertInstanceOf(ImageInterface::class, $image); - - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $this->assertEquals(5, $image->loops()); - $this->assertEquals(2, $image->count()); - } - - public function testHandleInputImage(): void - { - $result = $this->driver->handleInput($this->getTestResourcePath('test.jpg')); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testHandleInputColor(): void - { - $result = $this->driver->handleInput('ffffff'); - $this->assertInstanceOf(ColorInterface::class, $result); - } - - public function testHandleInputObjects(): void - { - $result = $this->driver->handleInput('ffffff', [ - new HexColorDecoder() - ]); - $this->assertInstanceOf(ColorInterface::class, $result); - } - - public function testHandleInputClassnames(): void - { - $result = $this->driver->handleInput('ffffff', [ - HexColorDecoder::class - ]); - $this->assertInstanceOf(ColorInterface::class, $result); - } - - public function testColorProcessor(): void - { - $result = $this->driver->colorProcessor(new Colorspace()); - $this->assertInstanceOf(ColorProcessorInterface::class, $result); - } - - #[DataProvider('supportsDataProvider')] - public function testSupports(bool $result, mixed $identifier): void - { - $this->assertEquals($result, $this->driver->supports($identifier)); - } - - public static function supportsDataProvider(): array - { - return [ - [true, Format::JPEG], - [true, MediaType::IMAGE_JPEG], - [true, MediaType::IMAGE_JPG], - [true, FileExtension::JPG], - [true, FileExtension::JPEG], - [true, 'jpg'], - [true, 'jpeg'], - [true, 'image/jpg'], - [true, 'image/jpeg'], - - [true, Format::WEBP], - [true, MediaType::IMAGE_WEBP], - [true, MediaType::IMAGE_X_WEBP], - [true, FileExtension::WEBP], - [true, 'webp'], - [true, 'image/webp'], - [true, 'image/x-webp'], - - [true, Format::GIF], - [true, MediaType::IMAGE_GIF], - [true, FileExtension::GIF], - [true, 'gif'], - [true, 'image/gif'], - - [true, Format::PNG], - [true, MediaType::IMAGE_PNG], - [true, MediaType::IMAGE_X_PNG], - [true, FileExtension::PNG], - [true, 'png'], - [true, 'image/png'], - [true, 'image/x-png'], - - [true, Format::AVIF], - [true, MediaType::IMAGE_AVIF], - [true, MediaType::IMAGE_X_AVIF], - [true, FileExtension::AVIF], - [true, 'avif'], - [true, 'image/avif'], - [true, 'image/x-avif'], - - [true, Format::BMP], - [true, FileExtension::BMP], - [true, MediaType::IMAGE_BMP], - [true, MediaType::IMAGE_MS_BMP], - [true, MediaType::IMAGE_X_BITMAP], - [true, MediaType::IMAGE_X_BMP], - [true, MediaType::IMAGE_X_MS_BMP], - [true, MediaType::IMAGE_X_WINDOWS_BMP], - [true, MediaType::IMAGE_X_WIN_BITMAP], - [true, MediaType::IMAGE_X_XBITMAP], - [true, 'bmp'], - [true, 'image/bmp'], - [true, 'image/ms-bmp'], - [true, 'image/x-bitmap'], - [true, 'image/x-bmp'], - [true, 'image/x-ms-bmp'], - [true, 'image/x-windows-bmp'], - [true, 'image/x-win-bitmap'], - [true, 'image/x-xbitmap'], - - [true, Format::TIFF], - [true, MediaType::IMAGE_TIFF], - [true, FileExtension::TIFF], - [true, FileExtension::TIF], - [true, 'tif'], - [true, 'tiff'], - [true, 'image/tiff'], - - [true, Format::JP2], - [true, MediaType::IMAGE_JP2], - [true, MediaType::IMAGE_JPX], - [true, MediaType::IMAGE_JPM], - [true, FileExtension::TIFF], - [true, FileExtension::TIF], - [true, FileExtension::JP2], - [true, FileExtension::J2K], - [true, FileExtension::JPF], - [true, FileExtension::JPM], - [true, FileExtension::JPG2], - [true, FileExtension::J2C], - [true, FileExtension::JPC], - [true, FileExtension::JPX], - [true, 'jp2'], - [true, 'j2k'], - [true, 'jpf'], - [true, 'jpm'], - [true, 'jpg2'], - [true, 'j2c'], - [true, 'jpc'], - [true, 'jpx'], - - [true, Format::HEIC], - [true, MediaType::IMAGE_HEIC], - [true, MediaType::IMAGE_HEIF], - [true, FileExtension::HEIC], - [true, FileExtension::HEIF], - [true, 'heic'], - [true, 'heif'], - [true, 'image/heic'], - [true, 'image/heif'], - - [false, 'tga'], - [false, 'image/tga'], - [false, 'image/x-targa'], - [false, 'foo'], - [false, ''], - ]; - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php deleted file mode 100644 index b425a2f3..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new AvifEncoder(10); - $result = $encoder->encode($image); - $this->assertMediaType('image/avif', $result); - $this->assertEquals('image/avif', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php deleted file mode 100644 index 2ac9f962..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new BmpEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], $result); - $this->assertEquals('image/bmp', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php deleted file mode 100644 index 7085f95b..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php +++ /dev/null @@ -1,53 +0,0 @@ -createTestImage(3, 2); - $encoder = new GifEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType('image/gif', $result); - $this->assertEquals('image/gif', $result->mimetype()); - $this->assertFalse( - Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() - ); - } - - public function testEncodeInterlaced(): void - { - $image = $this->createTestImage(3, 2); - $encoder = new GifEncoder(interlaced: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/gif', $result); - $this->assertEquals('image/gif', $result->mimetype()); - $this->assertTrue( - Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() - ); - } - - public function testEncodeInterlacedAnimation(): void - { - $image = $this->createTestAnimation(); - $encoder = new GifEncoder(interlaced: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/gif', $result); - $this->assertEquals('image/gif', $result->mimetype()); - $this->assertTrue( - Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() - ); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php deleted file mode 100644 index b3843dad..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new HeicEncoder(75); - $result = $encoder->encode($image); - $this->assertMediaType('image/heic', $result); - $this->assertEquals('image/heic', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php deleted file mode 100644 index 689604a4..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new Jpeg2000Encoder(75); - $result = $encoder->encode($image); - $this->assertMediaType('image/jp2', $result); - $this->assertEquals('image/jp2', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php deleted file mode 100644 index 79285fc6..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php +++ /dev/null @@ -1,38 +0,0 @@ -createTestImage(3, 2); - $encoder = new JpegEncoder(75); - $result = $encoder->encode($image); - $this->assertMediaType('image/jpeg', $result); - $this->assertEquals('image/jpeg', $result->mimetype()); - } - - public function testEncodeProgressive(): void - { - $image = $this->createTestImage(3, 2); - $encoder = new JpegEncoder(progressive: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/jpeg', $result); - $this->assertEquals('image/jpeg', $result->mimetype()); - $this->assertTrue($this->isProgressiveJpeg($result)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php deleted file mode 100644 index 5684bb1c..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php +++ /dev/null @@ -1,102 +0,0 @@ -createTestImage(3, 2); - $encoder = new PngEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType('image/png', $result); - $this->assertEquals('image/png', $result->mimetype()); - $this->assertFalse($this->isInterlacedPng($result)); - } - - public function testEncodeInterlaced(): void - { - $image = $this->createTestImage(3, 2); - $encoder = new PngEncoder(interlaced: true); - $result = $encoder->encode($image); - $this->assertMediaType('image/png', $result); - $this->assertEquals('image/png', $result->mimetype()); - $this->assertTrue($this->isInterlacedPng($result)); - } - - #[DataProvider('indexedDataProvider')] - public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, string $result): void - { - $this->assertEquals( - $result, - $this->pngColorType($encoder->encode($image)), - ); - } - - public static function indexedDataProvider(): array - { - return [ - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: true), - 'indexed', - ], - - [ - static::createTestImage(3, 2)->fill('ccc'), // new grayscale - new PngEncoder(indexed: true), - 'grayscale', // result should be 'indexed' but there seems to be no way to force this with imagick - ], - [ - static::readTestImage('circle.png'), // truecolor-alpha - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('circle.png'), // indexedcolor-alpha - new PngEncoder(indexed: true), - 'grayscale-alpha', // result should be 'indexed' but there seems to be no way to force this with imagick - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: true), - 'indexed', - ], - ]; - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php deleted file mode 100644 index 25cf769c..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new TiffEncoder(); - $result = $encoder->encode($image); - $this->assertMediaType('image/tiff', $result); - $this->assertEquals('image/tiff', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php deleted file mode 100644 index 89f3b39f..00000000 --- a/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createTestImage(3, 2); - $encoder = new WebpEncoder(75); - $result = $encoder->encode($image); - $this->assertMediaType('image/webp', $result); - $this->assertEquals('image/webp', $result->mimetype()); - } -} diff --git a/tests/Unit/Drivers/Imagick/FontProcessorTest.php b/tests/Unit/Drivers/Imagick/FontProcessorTest.php deleted file mode 100644 index cb80e97a..00000000 --- a/tests/Unit/Drivers/Imagick/FontProcessorTest.php +++ /dev/null @@ -1,74 +0,0 @@ -boxSize( - 'ABC', - $this->testFont()->setSize(120), - ); - - $this->assertInstanceOf(SizeInterface::class, $size); - $this->assertEquals(163, $size->width()); - $this->assertEquals(72, $size->height()); - } - - public function testNativeFontSize(): void - { - $processor = new FontProcessor(); - $font = new Font(); - $font->setSize(14.2); - $size = $processor->nativeFontSize($font); - $this->assertEquals(14.2, $size); - } - - public function testTextBlock(): void - { - $processor = new FontProcessor(); - $result = $processor->textBlock( - 'test', - $this->testFont(), - new Point(0, 0), - ); - $this->assertInstanceOf(TextBlock::class, $result); - } - - public function testTypographicalSize(): void - { - $processor = new FontProcessor(); - $result = $processor->typographicalSize($this->testFont()); - $this->assertEquals(7, $result); - } - - public function testCapHeight(): void - { - $processor = new FontProcessor(); - $result = $processor->capHeight($this->testFont()); - $this->assertEquals(7, $result); - } - - public function testLeading(): void - { - $processor = new FontProcessor(); - $result = $processor->leading($this->testFont()); - $this->assertEquals(9, $result); - } - - private function testFont(): Font - { - return new Font($this->getTestResourcePath('test.ttf')); - } -} diff --git a/tests/Unit/Drivers/Imagick/FrameTest.php b/tests/Unit/Drivers/Imagick/FrameTest.php deleted file mode 100644 index 632dce40..00000000 --- a/tests/Unit/Drivers/Imagick/FrameTest.php +++ /dev/null @@ -1,102 +0,0 @@ -newImage(3, 2, new ImagickPixel('red'), 'png'); - $imagick->setImageDelay(125); // 1.25 seconds - $imagick->setImageDispose(5); - $imagick->setImagePage(3, 2, 8, 9); - - return new Frame($imagick); - } - - public function testConstructor(): void - { - $frame = $this->getTestFrame(); - $this->assertInstanceOf(Frame::class, $frame); - } - - public function testGetSize(): void - { - $frame = $this->getTestFrame(); - $this->assertInstanceOf(Rectangle::class, $frame->size()); - } - - public function testSetGetDelay(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(1.25, $frame->delay()); - - $result = $frame->setDelay(2.5); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(2.5, $frame->delay()); - $this->assertEquals(250, $frame->native()->getImageDelay()); - } - - public function testSetGetDispose(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(5, $frame->dispose()); - - $result = $frame->setDispose(100); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->dispose()); - } - - public function testSetGetOffsetLeft(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(8, $frame->offsetLeft()); - - $result = $frame->setOffsetLeft(100); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->offsetLeft()); - } - - public function testSetGetOffsetTop(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(9, $frame->offsetTop()); - - $result = $frame->setOffsetTop(100); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->offsetTop()); - } - - public function testSetGetOffset(): void - { - $frame = $this->getTestFrame(); - $this->assertEquals(8, $frame->offsetLeft()); - $this->assertEquals(9, $frame->offsetTop()); - - $result = $frame->setOffset(100, 200); - $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->offsetLeft()); - $this->assertEquals(200, $frame->offsetTop()); - } - - public function testToImage(): void - { - $frame = $this->getTestFrame(); - $this->assertInstanceOf(Image::class, $frame->toImage(new Driver())); - } -} diff --git a/tests/Unit/Drivers/Imagick/ImageTest.php b/tests/Unit/Drivers/Imagick/ImageTest.php deleted file mode 100644 index 2a83c560..00000000 --- a/tests/Unit/Drivers/Imagick/ImageTest.php +++ /dev/null @@ -1,391 +0,0 @@ -readImage($this->getTestResourcePath('animation.gif')); - $this->image = new Image( - new Driver(), - new Core($imagick), - new Collection([ - 'test' => 'foo' - ]), - ); - } - - public function testClone(): void - { - $image = $this->readTestImage('gradient.gif'); - $clone = clone $image; - - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $clone->width()); - $result = $clone->crop(4, 4); - $this->assertEquals(16, $image->width()); - $this->assertEquals(4, $clone->width()); - $this->assertEquals(4, $result->width()); - - $this->assertEquals('ff0000', $image->pickColor(0, 0)->toHex()); - $this->assertTransparency($image->pickColor(1, 0)); - - $this->assertEquals('ff0000', $clone->pickColor(0, 0)->toHex()); - $this->assertTransparency($clone->pickColor(1, 0)); - } - - public function testDriver(): void - { - $this->assertInstanceOf(Driver::class, $this->image->driver()); - } - - public function testCore(): void - { - $this->assertInstanceOf(Core::class, $this->image->core()); - } - - public function testCount(): void - { - $this->assertEquals(8, $this->image->count()); - } - - public function testIteration(): void - { - foreach ($this->image as $frame) { - $this->assertInstanceOf(Frame::class, $frame); - } - } - - public function testIsAnimated(): void - { - $this->assertTrue($this->image->isAnimated()); - } - - public function testSetGetLoops(): void - { - $this->assertEquals(3, $this->image->loops()); - $result = $this->image->setLoops(10); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals(10, $this->image->loops()); - } - - public function testSetGetOrigin(): void - { - $origin = $this->image->origin(); - $this->assertInstanceOf(Origin::class, $origin); - $this->image->setOrigin(new Origin('test1', 'test2')); - $this->assertInstanceOf(Origin::class, $this->image->origin()); - $this->assertEquals('test1', $this->image->origin()->mimetype()); - $this->assertEquals('test2', $this->image->origin()->filePath()); - } - - public function testRemoveAnimation(): void - { - $this->assertTrue($this->image->isAnimated()); - $result = $this->image->removeAnimation(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertFalse($this->image->isAnimated()); - } - - public function testSliceAnimation(): void - { - $this->assertEquals(8, $this->image->count()); - $result = $this->image->sliceAnimation(0, 2); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals(2, $this->image->count()); - } - - public function testExif(): void - { - $this->assertInstanceOf(Collection::class, $this->image->exif()); - $this->assertEquals('foo', $this->image->exif('test')); - } - - public function testModify(): void - { - $result = $this->image->modify(new GreyscaleModifier()); - $this->assertInstanceOf(Image::class, $result); - } - - public function testAnalyze(): void - { - $result = $this->image->analyze(new WidthAnalyzer()); - $this->assertEquals(20, $result); - } - - public function testEncode(): void - { - $result = $this->image->encode(new PngEncoder()); - $this->assertInstanceOf(EncodedImage::class, $result); - } - - public function testAutoEncode(): void - { - $result = $this->readTestImage('blue.gif')->encode(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - } - - public function testEncodeByMediaType(): void - { - $result = $this->readTestImage('blue.gif')->encodeByMediaType(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - - $result = $this->readTestImage('blue.gif')->encodeByMediaType('image/png'); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - } - - public function testEncodeByExtension(): void - { - $result = $this->readTestImage('blue.gif')->encodeByExtension(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - - $result = $this->readTestImage('blue.gif')->encodeByExtension('png'); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - } - - public function testEncodeByPath(): void - { - $result = $this->readTestImage('blue.gif')->encodeByPath(); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/gif', $result); - - $result = $this->readTestImage('blue.gif')->encodeByPath('foo/bar.png'); - $this->assertInstanceOf(EncodedImage::class, $result); - $this->assertMediaType('image/png', $result); - } - - public function testSaveAsFormat(): void - { - $path = __DIR__ . '/tmp.png'; - $result = $this->readTestImage('blue.gif')->save($path); - $this->assertInstanceOf(Image::class, $result); - $this->assertFileExists($path); - $this->assertMediaType('image/png', file_get_contents($path)); - unlink($path); - } - - public function testSaveFallback(): void - { - $path = __DIR__ . '/tmp.unknown'; - $result = $this->readTestImage('blue.gif')->save($path); - $this->assertInstanceOf(Image::class, $result); - $this->assertFileExists($path); - $this->assertMediaType('image/gif', file_get_contents($path)); - unlink($path); - } - - public function testSaveUndeterminedPath(): void - { - $this->expectException(EncoderException::class); - $this->createTestImage(2, 3)->save(); - } - - public function testWidthHeightSize(): void - { - $this->assertEquals(20, $this->image->width()); - $this->assertEquals(15, $this->image->height()); - $this->assertInstanceOf(SizeInterface::class, $this->image->size()); - } - - public function testSetGetColorspace(): void - { - $this->assertInstanceOf(ColorspaceInterface::class, $this->image->colorspace()); - $this->assertInstanceOf(RgbColorspace::class, $this->image->colorspace()); - $result = $this->image->setColorspace(CmykColorspace::class); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertInstanceOf(CmykColorspace::class, $this->image->colorspace()); - } - - public function testSetGetResolution(): void - { - $resolution = $this->image->resolution(); - $this->assertInstanceOf(ResolutionInterface::class, $resolution); - $this->assertEquals(0, $resolution->x()); - $this->assertEquals(0, $resolution->y()); - $result = $this->image->setResolution(300, 300); - $resolution = $this->image->resolution(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals(300, $resolution->x()); - $this->assertEquals(300, $resolution->y()); - } - - public function testPickColor(): void - { - $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0)); - $this->assertInstanceOf(ColorInterface::class, $this->image->pickColor(0, 0, 1)); - } - - public function testPickColors(): void - { - $result = $this->image->pickColors(0, 0); - $this->assertInstanceOf(Collection::class, $result); - $this->assertEquals(8, $result->count()); - } - - public function testProfile(): void - { - $this->expectException(ColorException::class); - $this->image->profile(); - } - - public function testReduceColors(): void - { - $image = $this->readTestImage(); - $result = $image->reduceColors(8); - $this->assertInstanceOf(ImageInterface::class, $result); - } - - public function testSharpen(): void - { - $this->assertInstanceOf(Image::class, $this->image->sharpen(12)); - } - - public function testBlendTransparencyDefault(): void - { - $image = $this->readTestImage('gradient.gif'); - $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); - $result = $image->blendTransparency(); - $this->assertColor(255, 255, 255, 255, $image->pickColor(1, 0)); - $this->assertColor(255, 255, 255, 255, $result->pickColor(1, 0)); - } - - public function testBlendTransparencyArgument(): void - { - $image = $this->readTestImage('gradient.gif'); - $this->assertColor(0, 0, 0, 0, $image->pickColor(1, 0)); - $result = $image->blendTransparency('ff5500'); - $this->assertColor(255, 85, 0, 255, $image->pickColor(1, 0)); - $this->assertColor(255, 85, 0, 255, $result->pickColor(1, 0)); - } - - public function testToJpeg(): void - { - $this->assertMediaType('image/jpeg', $this->image->toJpeg()); - $this->assertMediaType('image/jpeg', $this->image->toJpg()); - } - - public function testToJpeg2000(): void - { - $this->assertMediaType('image/jp2', $this->image->toJpeg2000()); - $this->assertMediaType('image/jp2', $this->image->toJp2()); - } - - public function testToPng(): void - { - $this->assertMediaType('image/png', $this->image->toPng()); - } - - public function testToGif(): void - { - $this->assertMediaType('image/gif', $this->image->toGif()); - } - - public function testToWebp(): void - { - $this->assertMediaType('image/webp', $this->image->toWebp()); - } - - public function testToBitmap(): void - { - $this->assertMediaTypeBitmap($this->image->toBitmap()); - $this->assertMediaTypeBitmap($this->image->toBmp()); - } - - public function testToAvif(): void - { - $this->assertMediaType('image/avif', $this->image->toAvif()); - } - - public function testToTiff(): void - { - $this->assertMediaType('image/tiff', $this->image->toTiff()); - $this->assertMediaType('image/tiff', $this->image->toTif()); - } - - public function testToHeic(): void - { - $this->assertMediaType('image/heic', $this->image->toHeic()); - } - - public function testInvert(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); - $result = $image->invert(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); - } - - public function testPixelate(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - - $result = $image->pixelate(10); - $this->assertInstanceOf(ImageInterface::class, $result); - - list($r, $g, $b) = $image->pickColor(0, 0)->toArray(); - $this->assertEquals(0, $r); - $this->assertEquals(174, $g); - $this->assertEquals(240, $b); - - list($r, $g, $b) = $image->pickColor(14, 14)->toArray(); - $this->assertEquals(107, $r); - $this->assertEquals(171, $g); - $this->assertEquals(140, $b); - } - - public function testGreyscale(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); - $result = $image->greyscale(); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); - } - - public function testBrightness(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $result = $image->brightness(30); - $this->assertInstanceOf(ImageInterface::class, $result); - $this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php deleted file mode 100644 index b0929cdb..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/BlurModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new BlurModifier(30)); - $this->assertEquals('42acb2', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/BrightnessModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/BrightnessModifierTest.php deleted file mode 100644 index 461e5d7e..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/BrightnessModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new BrightnessModifier(30)); - $this->assertEquals('39c9ff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ColorizeModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ColorizeModifierTest.php deleted file mode 100644 index 2b971cdf..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ColorizeModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('tile.png'); - $image = $image->modify(new ColorizeModifier(100, -100, -100)); - $this->assertColor(251, 0, 0, 255, $image->pickColor(5, 5)); - $this->assertColor(239, 0, 0, 255, $image->pickColor(15, 15)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php deleted file mode 100644 index 215487a3..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ContainModifierTest.php +++ /dev/null @@ -1,34 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $result = $image->modify(new ContainModifier(200, 100, 'ff0')); - $this->assertEquals(200, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(0, 0, 0, 0, $image->pickColor(140, 10)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(175, 10)); - $this->assertEquals(200, $result->width()); - $this->assertEquals(100, $result->height()); - $this->assertColor(255, 255, 0, 255, $result->pickColor(0, 0)); - $this->assertColor(0, 0, 0, 0, $result->pickColor(140, 10)); - $this->assertColor(255, 255, 0, 255, $result->pickColor(175, 10)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ContrastModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ContrastModifierTest.php deleted file mode 100644 index 3c5519a1..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ContrastModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new ContrastModifier(30)); - $this->assertEquals('00fcff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/CoverDownModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/CoverDownModifierTest.php deleted file mode 100644 index 2ffdfc96..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/CoverDownModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new CoverDownModifier(100, 100, 'center')); - $this->assertEquals(100, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); - $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); - $this->assertTransparency($image->pickColor(90, 30)); - } - - public function testModifyOddSize(): void - { - $image = $this->createTestImage(375, 250); - $image->modify(new CoverDownModifier(240, 90, 'center')); - $this->assertEquals(240, $image->width()); - $this->assertEquals(90, $image->height()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php deleted file mode 100644 index 87523dbd..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/CoverModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new CoverModifier(100, 100, 'center')); - $this->assertEquals(100, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(90, 90)); - $this->assertColor(0, 255, 0, 255, $image->pickColor(65, 70)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(70, 52)); - $this->assertTransparency($image->pickColor(90, 30)); - } - - public function testModifyOddSize(): void - { - $image = $this->createTestImage(375, 250); - $image->modify(new CoverModifier(240, 90, 'center')); - $this->assertEquals(240, $image->width()); - $this->assertEquals(90, $image->height()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php deleted file mode 100644 index 2b3691f7..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/CropModifierTest.php +++ /dev/null @@ -1,39 +0,0 @@ -readTestImage('blocks.png'); - $image = $image->modify(new CropModifier(200, 200, 0, 0, 'ffffff', 'bottom-right')); - $this->assertEquals(200, $image->width()); - $this->assertEquals(200, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(5, 5)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(100, 100)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(190, 190)); - } - - public function testModifyExtend(): void - { - $image = $this->readTestImage('blocks.png'); - $image = $image->modify(new CropModifier(800, 100, -10, -10, 'ff0000', 'top-left')); - $this->assertEquals(800, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(9, 9)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(16, 16)); - $this->assertColor(0, 0, 255, 255, $image->pickColor(445, 16)); - $this->assertTransparency($image->pickColor(460, 16)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/DrawBezierModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/DrawBezierModifierTest.php deleted file mode 100644 index 107482be..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/DrawBezierModifierTest.php +++ /dev/null @@ -1,33 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $drawable = new Bezier([ - new Point(0, 0), - new Point(15, 0), - new Point(15, 15), - new Point(0, 15) - ]); - $drawable->setBackgroundColor('b53717'); - $image->modify(new DrawBezierModifier($drawable)); - $this->assertEquals('b53717', $image->pickColor(5, 5)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/DrawEllipseModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/DrawEllipseModifierTest.php deleted file mode 100644 index 71da4e74..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/DrawEllipseModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $drawable = new Ellipse(10, 10, new Point(14, 14)); - $drawable->setBackgroundColor('b53717'); - $image->modify(new DrawEllipseModifier($drawable)); - $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/DrawLineModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/DrawLineModifierTest.php deleted file mode 100644 index 645c7eed..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/DrawLineModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $line = new Line(new Point(0, 0), new Point(10, 0), 4); - $line->setBackgroundColor('b53517'); - $image->modify(new DrawLineModifier($line)); - $this->assertEquals('b53517', $image->pickColor(0, 0)->toHex()); - } - - public function testApplyTransparent(): void - { - $image = $this->createTestImage(10, 10)->fill('ff5500'); - $this->assertColor(255, 85, 0, 255, $image->pickColor(5, 5)); - $line = new Line(new Point(0, 5), new Point(10, 5), 4); - $line->setBackgroundColor('fff4'); - $image->modify(new DrawLineModifier($line)); - $this->assertColor(255, 136, 77, 255, $image->pickColor(5, 5)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/DrawPixelModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/DrawPixelModifierTest.php deleted file mode 100644 index d68d905f..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/DrawPixelModifierTest.php +++ /dev/null @@ -1,25 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new DrawPixelModifier(new Point(14, 14), 'ffffff')); - $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/DrawPolygonModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/DrawPolygonModifierTest.php deleted file mode 100644 index 36305db7..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/DrawPolygonModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $drawable = new Polygon([new Point(0, 0), new Point(15, 15), new Point(20, 20)]); - $drawable->setBackgroundColor('b53717'); - $image->modify(new DrawPolygonModifier($drawable)); - $this->assertEquals('b53717', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/DrawRectangleModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/DrawRectangleModifierTest.php deleted file mode 100644 index 158a3643..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/DrawRectangleModifierTest.php +++ /dev/null @@ -1,28 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $rectangle = new Rectangle(300, 200, new Point(14, 14)); - $rectangle->setBackgroundColor('ffffff'); - $image->modify(new DrawRectangleModifier($rectangle)); - $this->assertEquals('ffffff', $image->pickColor(14, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php deleted file mode 100644 index 6157b2ab..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/FillModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); - $image->modify(new FillModifier(new Color(204, 204, 204), new Point(540, 400))); - $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); - } - - public function testFillAllColor(): void - { - $image = $this->readTestImage('blocks.png'); - $this->assertEquals('0000ff', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('ff0000', $image->pickColor(540, 400)->toHex()); - $image->modify(new FillModifier(new Color(204, 204, 204))); - $this->assertEquals('cccccc', $image->pickColor(420, 270)->toHex()); - $this->assertEquals('cccccc', $image->pickColor(540, 400)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php deleted file mode 100644 index 0663aacb..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php +++ /dev/null @@ -1,35 +0,0 @@ -readTestImage('tile.png'); - $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); - $image->modify(new FlipModifier()); - $this->assertEquals('00000000', $image->pickColor(0, 0)->toHex()); - } - - public function testFlopImage(): void - { - $image = $this->readTestImage('tile.png'); - $this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex()); - $image->modify(new FlopModifier()); - $this->assertEquals('00000000', $image->pickColor(0, 0)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php deleted file mode 100644 index 2bf6377a..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/GammaModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $image->modify(new GammaModifier(2.1)); - $this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/GreyscaleModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/GreyscaleModifierTest.php deleted file mode 100644 index 52d7d8bc..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/GreyscaleModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertFalse($image->pickColor(0, 0)->isGreyscale()); - $image->modify(new GreyscaleModifier()); - $this->assertTrue($image->pickColor(0, 0)->isGreyscale()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php deleted file mode 100644 index 10697986..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/InvertModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('ffa601', $image->pickColor(25, 25)->toHex()); - $image->modify(new InvertModifier()); - $this->assertEquals('ff510f', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('0059fe', $image->pickColor(25, 25)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/PixelateModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/PixelateModifierTest.php deleted file mode 100644 index ce897587..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/PixelateModifierTest.php +++ /dev/null @@ -1,34 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex()); - $this->assertEquals('00aef0', $image->pickColor(14, 14)->toHex()); - $image->modify(new PixelateModifier(10)); - - list($r, $g, $b) = $image->pickColor(0, 0)->toArray(); - $this->assertEquals(0, $r); - $this->assertEquals(174, $g); - $this->assertEquals(240, $b); - - list($r, $g, $b) = $image->pickColor(14, 14)->toArray(); - $this->assertEquals(107, $r); - $this->assertEquals(171, $g); - $this->assertEquals(140, $b); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php deleted file mode 100644 index 5a6c0192..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/PlaceModifierTest.php +++ /dev/null @@ -1,42 +0,0 @@ -readTestImage('test.jpg'); - $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); - $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0)); - $this->assertEquals('33260e', $image->pickColor(300, 25)->toHex()); - } - - public function testColorChangeOpacityPng(): void - { - $image = $this->readTestImage('test.jpg'); - $this->assertEquals('febc44', $image->pickColor(300, 25)->toHex()); - $image->modify(new PlaceModifier($this->getTestResourcePath('circle.png'), 'top-right', 0, 0, 50)); - $this->assertColor(152, 112, 40, 255, $image->pickColor(300, 25), tolerance: 1); - $this->assertColor(255, 202, 107, 255, $image->pickColor(274, 5), tolerance: 1); - } - - public function testColorChangeOpacityJpeg(): void - { - $image = $this->createTestImage(16, 16)->fill('0000ff'); - $this->assertEquals('0000ff', $image->pickColor(10, 10)->toHex()); - $image->modify(new PlaceModifier($this->getTestResourcePath('exif.jpg'), opacity: 50)); - $this->assertColor(127, 83, 127, 255, $image->pickColor(10, 10), tolerance: 1); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php deleted file mode 100644 index e6c9d5ef..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/QuantizeColorsModifierTest.php +++ /dev/null @@ -1,40 +0,0 @@ -readTestImage('gradient.bmp'); - $this->assertEquals(15, $image->core()->native()->getImageColors()); - $image->modify(new QuantizeColorsModifier(4)); - $this->assertEquals(4, $image->core()->native()->getImageColors()); - } - - public function testNoColorReduction(): void - { - $image = $this->readTestImage('gradient.bmp'); - $this->assertEquals(15, $image->core()->native()->getImageColors()); - $image->modify(new QuantizeColorsModifier(150)); - $this->assertEquals(15, $image->core()->native()->getImageColors()); - } - - public function testInvalidColorInput(): void - { - $image = $this->readTestImage('gradient.bmp'); - $this->expectException(InputException::class); - $image->modify(new QuantizeColorsModifier(0)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/RemoveAnimationModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/RemoveAnimationModifierTest.php deleted file mode 100644 index 48bc3794..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/RemoveAnimationModifierTest.php +++ /dev/null @@ -1,42 +0,0 @@ -readTestImage('animation.gif'); - $this->assertEquals(8, count($image)); - $result = $image->modify(new RemoveAnimationModifier(2)); - $this->assertEquals(1, count($image)); - $this->assertEquals(1, count($result)); - } - - public function testApplyPercent(): void - { - $image = $this->readTestImage('animation.gif'); - $this->assertEquals(8, count($image)); - $result = $image->modify(new RemoveAnimationModifier('20%')); - $this->assertEquals(1, count($image)); - $this->assertEquals(1, count($result)); - } - - public function testApplyInvalid(): void - { - $image = $this->readTestImage('animation.gif'); - $this->expectException(InputException::class); - $image->modify(new RemoveAnimationModifier('test')); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php deleted file mode 100644 index a4d940e0..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasModifierTest.php +++ /dev/null @@ -1,69 +0,0 @@ -createTestImage(1, 1); - $this->assertEquals(1, $image->width()); - $this->assertEquals(1, $image->height()); - $image->modify(new ResizeCanvasModifier(3, 3, 'ff0', 'center')); - $this->assertEquals(3, $image->width()); - $this->assertEquals(3, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); - } - - public function testModifyWithTransparency(): void - { - $image = $this->readTestImage('tile.png'); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $image->modify(new ResizeCanvasModifier(18, 18, 'ff0', 'center')); - $this->assertEquals(18, $image->width()); - $this->assertEquals(18, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); - $this->assertTransparency($image->pickColor(12, 1)); - - $image = $this->createTestImage(16, 16)->fill('f00'); - $image->modify(new ResizeCanvasModifier(32, 32, '00f5', 'center')); - $this->assertEquals(32, $image->width()); - $this->assertEquals(32, $image->height()); - $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 5)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(16, 5)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 5)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 16)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(16, 16)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 16)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(5, 30)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(16, 30)); - $this->assertColor(0, 0, 255, 77, $image->pickColor(30, 30)); - } - - public function testModifyEdge(): void - { - $image = $this->createTestImage(1, 1); - $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); - $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom')); - $this->assertEquals(1, $image->width()); - $this->assertEquals(2, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 1)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifierTest.php deleted file mode 100644 index 466cb348..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ResizeCanvasRelativeModifierTest.php +++ /dev/null @@ -1,44 +0,0 @@ -createTestImage(1, 1); - $this->assertEquals(1, $image->width()); - $this->assertEquals(1, $image->height()); - $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); - $this->assertEquals(3, $image->width()); - $this->assertEquals(3, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(255, 0, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(2, 2)); - } - - public function testModifyWithTransparency(): void - { - $image = $this->readTestImage('tile.png'); - $this->assertEquals(16, $image->width()); - $this->assertEquals(16, $image->height()); - $image->modify(new ResizeCanvasRelativeModifier(2, 2, 'ff0', 'center')); - $this->assertEquals(18, $image->width()); - $this->assertEquals(18, $image->height()); - $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(1, 1)); - $this->assertColor(180, 224, 0, 255, $image->pickColor(2, 2)); - $this->assertColor(255, 255, 0, 255, $image->pickColor(17, 17)); - $this->assertTransparency($image->pickColor(12, 1)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php deleted file mode 100644 index 5441116d..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ResizeModifierTest.php +++ /dev/null @@ -1,27 +0,0 @@ -readTestImage('blocks.png'); - $this->assertEquals(640, $image->width()); - $this->assertEquals(480, $image->height()); - $image->modify(new ResizeModifier(200, 100)); - $this->assertEquals(200, $image->width()); - $this->assertEquals(100, $image->height()); - $this->assertColor(255, 0, 0, 255, $image->pickColor(150, 70)); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/ResolutionModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/ResolutionModifierTest.php deleted file mode 100644 index 1ced8dea..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/ResolutionModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('test.jpg'); - $this->assertEquals(72.0, $image->resolution()->x()); - $this->assertEquals(72.0, $image->resolution()->y()); - $image->modify(new ResolutionModifier(1, 2)); - $this->assertEquals(1.0, $image->resolution()->x()); - $this->assertEquals(2.0, $image->resolution()->y()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php deleted file mode 100644 index a280009c..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php +++ /dev/null @@ -1,26 +0,0 @@ -readTestImage('test.jpg'); - $this->assertEquals(320, $image->width()); - $this->assertEquals(240, $image->height()); - $image->modify(new RotateModifier(90, 'fff')); - $this->assertEquals(240, $image->width()); - $this->assertEquals(320, $image->height()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php deleted file mode 100644 index 4e0f35d3..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/SharpenModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals('60ab96', $image->pickColor(15, 14)->toHex()); - $image->modify(new SharpenModifier(10)); - $this->assertEquals('4faca6', $image->pickColor(15, 14)->toHex()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/TextModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/TextModifierTest.php deleted file mode 100644 index 232b6c3e..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/TextModifierTest.php +++ /dev/null @@ -1,37 +0,0 @@ -setColor('ff0055'); - - $modifier = new class ('test', new Point(), $font) extends TextModifier - { - public function test() - { - return $this->textColor(); - } - }; - - $modifier->setDriver(new Driver()); - - $this->assertInstanceOf(ColorInterface::class, $modifier->test()); - } -} diff --git a/tests/Unit/Drivers/Imagick/Modifiers/TrimModifierTest.php b/tests/Unit/Drivers/Imagick/Modifiers/TrimModifierTest.php deleted file mode 100644 index cd2bafdd..00000000 --- a/tests/Unit/Drivers/Imagick/Modifiers/TrimModifierTest.php +++ /dev/null @@ -1,55 +0,0 @@ -readTestImage('trim.png'); - $this->assertEquals(50, $image->width()); - $this->assertEquals(50, $image->height()); - $image->modify(new TrimModifier()); - $this->assertEquals(28, $image->width()); - $this->assertEquals(28, $image->height()); - } - - public function testTrimGradient(): void - { - $image = $this->readTestImage('radial.png'); - $this->assertEquals(50, $image->width()); - $this->assertEquals(50, $image->height()); - $image->modify(new TrimModifier(50)); - $this->assertEquals(29, $image->width()); - $this->assertEquals(29, $image->height()); - } - - public function testTrimHighTolerance(): void - { - $image = $this->readTestImage('trim.png'); - $this->assertEquals(50, $image->width()); - $this->assertEquals(50, $image->height()); - $image->modify(new TrimModifier(1000000)); - $this->assertEquals(1, $image->width()); - $this->assertEquals(1, $image->height()); - $this->assertColor(255, 255, 255, 0, $image->pickColor(0, 0)); - } - - public function testTrimAnimated(): void - { - $image = $this->readTestImage('animation.gif'); - $this->expectException(NotSupportedException::class); - $image->modify(new TrimModifier()); - } -} diff --git a/tests/Unit/Drivers/SpecializableAnalyzerTest.php b/tests/Unit/Drivers/SpecializableAnalyzerTest.php deleted file mode 100644 index b6345718..00000000 --- a/tests/Unit/Drivers/SpecializableAnalyzerTest.php +++ /dev/null @@ -1,22 +0,0 @@ -makePartial(); - $image = Mockery::mock(ImageInterface::class); - $image->shouldReceive('analyze')->andReturn('test'); - $result = $analyzer->analyze($image); - $this->assertEquals('test', $result); - } -} diff --git a/tests/Unit/Drivers/SpecializableDecoderTest.php b/tests/Unit/Drivers/SpecializableDecoderTest.php deleted file mode 100644 index a6c5c3b9..00000000 --- a/tests/Unit/Drivers/SpecializableDecoderTest.php +++ /dev/null @@ -1,20 +0,0 @@ -makePartial(); - $this->expectException(DecoderException::class); - $decoder->decode(null); - } -} diff --git a/tests/Unit/Drivers/SpecializableModifierTest.php b/tests/Unit/Drivers/SpecializableModifierTest.php deleted file mode 100644 index bea67973..00000000 --- a/tests/Unit/Drivers/SpecializableModifierTest.php +++ /dev/null @@ -1,22 +0,0 @@ -makePartial(); - $image = Mockery::mock(ImageInterface::class); - $image->shouldReceive('modify')->andReturn($image); - $result = $modifier->apply($image); - $this->assertInstanceOf(ImageInterface::class, $result); - } -} diff --git a/tests/Unit/EncodedImageTest.php b/tests/Unit/EncodedImageTest.php deleted file mode 100644 index 9224d46b..00000000 --- a/tests/Unit/EncodedImageTest.php +++ /dev/null @@ -1,60 +0,0 @@ -assertInstanceOf(EncodedImage::class, $image); - } - - public function testSave(): void - { - $image = new EncodedImage('foo'); - $path = __DIR__ . '/foo.tmp'; - $this->assertFalse(file_exists($path)); - $image->save($path); - $this->assertTrue(file_exists($path)); - $this->assertEquals('foo', file_get_contents($path)); - unlink($path); - } - - public function testToDataUri(): void - { - $image = new EncodedImage('foo'); - $this->assertEquals('data:application/octet-stream;base64,Zm9v', $image->toDataUri()); - } - - public function testToString(): void - { - $image = new EncodedImage('foo'); - $this->assertEquals('foo', (string) $image); - } - - public function testMediaType(): void - { - $image = new EncodedImage('foo'); - $this->assertEquals('application/octet-stream', $image->mediaType()); - - $image = new EncodedImage($this->getTestResourceData(), 'image/jpeg'); - $this->assertEquals('image/jpeg', $image->mediaType()); - } - - public function testMimetype(): void - { - $image = new EncodedImage('foo'); - $this->assertEquals('application/octet-stream', $image->mimetype()); - - $image = new EncodedImage($this->getTestResourceData(), 'image/jpeg'); - $this->assertEquals('image/jpeg', $image->mimetype()); - } -} diff --git a/tests/Unit/Encoders/FileExtensionEncoderTest.php b/tests/Unit/Encoders/FileExtensionEncoderTest.php deleted file mode 100644 index 4e28d9fc..00000000 --- a/tests/Unit/Encoders/FileExtensionEncoderTest.php +++ /dev/null @@ -1,100 +0,0 @@ -encoderByFileExtension($extension); - } - }; - - return $encoder->test($extension); - } - - #[DataProvider('targetEncoderProvider')] - public function testEncoderByFileExtensionString( - string|FileExtension $fileExtension, - string $targetEncoderClassname, - ): void { - $this->assertInstanceOf( - $targetEncoderClassname, - $this->testEncoder($fileExtension), - ); - } - - public static function targetEncoderProvider(): array - { - return [ - ['webp', WebpEncoder::class], - ['avif', AvifEncoder::class], - ['jpeg', JpegEncoder::class], - ['jpg', JpegEncoder::class], - ['bmp', BmpEncoder::class], - ['gif', GifEncoder::class], - ['png', PngEncoder::class], - ['tiff', TiffEncoder::class], - ['tif', TiffEncoder::class], - ['jp2', Jpeg2000Encoder::class], - ['heic', HeicEncoder::class], - [FileExtension::WEBP, WebpEncoder::class], - [FileExtension::AVIF, AvifEncoder::class], - [FileExtension::JPG, JpegEncoder::class], - [FileExtension::BMP, BmpEncoder::class], - [FileExtension::GIF, GifEncoder::class], - [FileExtension::PNG, PngEncoder::class], - [FileExtension::TIF, TiffEncoder::class], - [FileExtension::TIFF, TiffEncoder::class], - [FileExtension::JP2, Jpeg2000Encoder::class], - [FileExtension::HEIC, HeicEncoder::class], - ]; - } - - public function testArgumentsNotSupportedByTargetEncoder(): void - { - $encoder = $this->testEncoder( - 'png', - [ - 'interlaced' => true, // is not ignored - 'quality' => 10, // is ignored because png encoder has no quality argument - ], - ); - - $this->assertInstanceOf(PngEncoder::class, $encoder); - $this->assertTrue($encoder->interlaced); - } - - public function testEncoderByFileExtensionUnknown(): void - { - $this->expectException(EncoderException::class); - $this->testEncoder('test'); - } -} diff --git a/tests/Unit/Encoders/MediaTypeEncoderTest.php b/tests/Unit/Encoders/MediaTypeEncoderTest.php deleted file mode 100644 index 713611ac..00000000 --- a/tests/Unit/Encoders/MediaTypeEncoderTest.php +++ /dev/null @@ -1,99 +0,0 @@ -encoderByMediaType($mediaType); - } - }; - - return $encoder->test($mediaType); - } - - #[DataProvider('targetEncoderProvider')] - public function testEncoderByMediaType( - string|MediaType $mediaType, - string $targetEncoderClassname, - ): void { - $this->assertInstanceOf( - $targetEncoderClassname, - $this->testEncoder($mediaType) - ); - } - - public static function targetEncoderProvider(): array - { - return [ - ['image/webp', WebpEncoder::class], - ['image/avif', AvifEncoder::class], - ['image/jpeg', JpegEncoder::class], - ['image/bmp', BmpEncoder::class], - ['image/gif', GifEncoder::class], - ['image/png', PngEncoder::class], - ['image/png', PngEncoder::class], - ['image/tiff', TiffEncoder::class], - ['image/jp2', Jpeg2000Encoder::class], - ['image/heic', HeicEncoder::class], - [MediaType::IMAGE_WEBP, WebpEncoder::class], - [MediaType::IMAGE_AVIF, AvifEncoder::class], - [MediaType::IMAGE_JPEG, JpegEncoder::class], - [MediaType::IMAGE_BMP, BmpEncoder::class], - [MediaType::IMAGE_GIF, GifEncoder::class], - [MediaType::IMAGE_PNG, PngEncoder::class], - [MediaType::IMAGE_TIFF, TiffEncoder::class], - [MediaType::IMAGE_JP2, Jpeg2000Encoder::class], - [MediaType::IMAGE_HEIC, HeicEncoder::class], - [MediaType::IMAGE_HEIF, HeicEncoder::class], - ]; - } - - public function testArgumentsNotSupportedByTargetEncoder(): void - { - $encoder = $this->testEncoder( - 'image/png', - [ - 'interlaced' => true, // is not ignored - 'quality' => 10, // is ignored because png encoder has no quality argument - ], - ); - - $this->assertInstanceOf(PngEncoder::class, $encoder); - $this->assertTrue($encoder->interlaced); - } - - public function testEncoderByFileExtensionUnknown(): void - { - $this->expectException(EncoderException::class); - $this->testEncoder('test'); - } -} diff --git a/tests/Unit/FileExtensionTest.php b/tests/Unit/FileExtensionTest.php deleted file mode 100644 index 4092aabb..00000000 --- a/tests/Unit/FileExtensionTest.php +++ /dev/null @@ -1,109 +0,0 @@ -assertEquals(Format::JPEG, $ext->format()); - - $ext = FileExtension::JPG; - $this->assertEquals(Format::JPEG, $ext->format()); - } - - public function testFormatWebp(): void - { - $ext = FileExtension::WEBP; - $this->assertEquals(Format::WEBP, $ext->format()); - } - - public function testFormatGif(): void - { - $ext = FileExtension::GIF; - $this->assertEquals(Format::GIF, $ext->format()); - } - - public function testFormatPng(): void - { - $ext = FileExtension::PNG; - $this->assertEquals(Format::PNG, $ext->format()); - } - - public function testFormatAvif(): void - { - $ext = FileExtension::AVIF; - $this->assertEquals(Format::AVIF, $ext->format()); - } - - public function testFormatBmp(): void - { - $ext = FileExtension::BMP; - $this->assertEquals(Format::BMP, $ext->format()); - } - - public function testFormatTiff(): void - { - $ext = FileExtension::TIFF; - $this->assertEquals(Format::TIFF, $ext->format()); - - $ext = FileExtension::TIF; - $this->assertEquals(Format::TIFF, $ext->format()); - } - - public function testFormatJpeg2000(): void - { - $ext = FileExtension::JP2; - $this->assertEquals(Format::JP2, $ext->format()); - - $ext = FileExtension::J2K; - $this->assertEquals(Format::JP2, $ext->format()); - - $ext = FileExtension::J2C; - $this->assertEquals(Format::JP2, $ext->format()); - - $ext = FileExtension::JPG2; - $this->assertEquals(Format::JP2, $ext->format()); - } - - public function testFormatHeic(): void - { - $ext = FileExtension::HEIC; - $this->assertEquals(Format::HEIC, $ext->format()); - - $ext = FileExtension::HEIF; - $this->assertEquals(Format::HEIC, $ext->format()); - } - - #[DataProvider('mediaTypesDataProvider')] - public function testMediatypes(FileExtension $extension, int $mediaTypeCount, MediaType $mediaType): void - { - $this->assertCount($mediaTypeCount, $extension->mediaTypes()); - $this->assertEquals($mediaType, $extension->mediaType()); - } - - public static function mediaTypesDataProvider(): array - { - return [ - [FileExtension::JPEG, 4, MediaType::IMAGE_JPEG], - [FileExtension::WEBP, 2, MediaType::IMAGE_WEBP], - [FileExtension::GIF, 1, MediaType::IMAGE_GIF], - [FileExtension::PNG, 2, MediaType::IMAGE_PNG], - [FileExtension::AVIF, 2, MediaType::IMAGE_AVIF], - [FileExtension::BMP, 8, MediaType::IMAGE_BMP], - [FileExtension::TIFF, 1, MediaType::IMAGE_TIFF], - [FileExtension::TIF, 1, MediaType::IMAGE_TIFF], - [FileExtension::JP2, 3, MediaType::IMAGE_JP2], - [FileExtension::HEIC, 3, MediaType::IMAGE_HEIC], - ]; - } -} diff --git a/tests/Unit/FileTest.php b/tests/Unit/FileTest.php deleted file mode 100644 index 79263c1d..00000000 --- a/tests/Unit/FileTest.php +++ /dev/null @@ -1,67 +0,0 @@ -assertInstanceOf(File::class, $file); - - $file = new File('foo'); - $this->assertInstanceOf(File::class, $file); - } - - public function testConstructorFromString(): void - { - $file = new File('foo'); - $this->assertInstanceOf(File::class, $file); - } - - public function testConstructorFromResource(): void - { - $file = new File(fopen('php://temp', 'r')); - $this->assertInstanceOf(File::class, $file); - } - - public function testSave(): void - { - $filename = __DIR__ . '/file_' . strval(hrtime(true)) . '.test'; - $file = new File('foo'); - $file->save($filename); - $this->assertTrue(file_exists($filename)); - unlink($filename); - } - - public function testToString(): void - { - $file = new File('foo'); - $string = $file->toString(); - $this->assertEquals('foo', $string); - $this->assertEquals('foo', (string) $string); - } - - public function testToFilePointer(): void - { - $file = new File('foo'); - $fp = $file->toFilePointer(); - $this->assertIsResource($fp); - } - - public function testSize(): void - { - $file = new File(); - $this->assertEquals(0, $file->size()); - - $file = new File('foo'); - $this->assertEquals(3, $file->size()); - } -} diff --git a/tests/Unit/FormatTest.php b/tests/Unit/FormatTest.php deleted file mode 100644 index e578397b..00000000 --- a/tests/Unit/FormatTest.php +++ /dev/null @@ -1,286 +0,0 @@ -assertEquals(Format::JPEG, Format::create(Format::JPEG)); - $this->assertEquals(Format::JPEG, Format::create('jpg')); - $this->assertEquals(Format::JPEG, Format::create('jpeg')); - $this->assertEquals(Format::JPEG, Format::create('image/jpeg')); - $this->assertEquals(Format::GIF, Format::create('image/gif')); - $this->assertEquals(Format::PNG, Format::create(FileExtension::PNG)); - $this->assertEquals(Format::WEBP, Format::create(MediaType::IMAGE_WEBP)); - } - - public function testCreateUnknown(): void - { - $this->expectException(NotSupportedException::class); - Format::create('foo'); - } - - public function testTryCreate(): void - { - $this->assertEquals(Format::JPEG, Format::tryCreate(Format::JPEG)); - $this->assertEquals(Format::JPEG, Format::tryCreate('jpg')); - $this->assertEquals(Format::JPEG, Format::tryCreate('jpeg')); - $this->assertEquals(Format::JPEG, Format::tryCreate('image/jpeg')); - $this->assertEquals(Format::GIF, Format::tryCreate('image/gif')); - $this->assertEquals(Format::PNG, Format::tryCreate(FileExtension::PNG)); - $this->assertEquals(Format::WEBP, Format::tryCreate(MediaType::IMAGE_WEBP)); - $this->assertNull(Format::tryCreate('no-format')); - } - - public function testMediaTypesJpeg(): void - { - $format = Format::JPEG; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(4, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_JPEG, $format->mediaType()); - } - - public function testMediaTypesWebp(): void - { - $format = Format::WEBP; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(2, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_WEBP, $format->mediaType()); - } - - public function testMediaTypesFGif(): void - { - $format = Format::GIF; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(1, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_GIF, $format->mediaType()); - } - - public function testMediaTypesPng(): void - { - $format = Format::PNG; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(2, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_PNG, $format->mediaType()); - } - - public function testMediaTypesAvif(): void - { - $format = Format::AVIF; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(2, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_AVIF, $format->mediaType()); - } - - public function testMediaTypesBmp(): void - { - $format = Format::BMP; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(8, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_BMP, $format->mediaType()); - } - - public function testMediaTypesTiff(): void - { - $format = Format::TIFF; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(1, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_TIFF, $format->mediaType()); - } - - public function testMediaTypesJpeg2000(): void - { - $format = Format::JP2; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(3, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_JP2, $format->mediaType()); - } - - public function testMediaTypesHeic(): void - { - $format = Format::HEIC; - $mediaTypes = $format->mediaTypes(); - $this->assertIsArray($mediaTypes); - $this->assertCount(3, $mediaTypes); - - $this->assertEquals(MediaType::IMAGE_HEIC, $format->mediaType()); - } - - public function testEncoderJpeg(): void - { - $format = Format::JPEG; - $this->assertInstanceOf(JpegEncoder::class, $format->encoder()); - } - - public function testEncoderAvif(): void - { - $format = Format::AVIF; - $this->assertInstanceOf(AvifEncoder::class, $format->encoder()); - } - - public function testEncoderWebp(): void - { - $format = Format::WEBP; - $this->assertInstanceOf(WebpEncoder::class, $format->encoder()); - } - - public function testEncoderGif(): void - { - $format = Format::GIF; - $this->assertInstanceOf(GifEncoder::class, $format->encoder()); - } - - public function testEncoderPng(): void - { - $format = Format::PNG; - $this->assertInstanceOf(PngEncoder::class, $format->encoder()); - } - - public function testEncoderBitmap(): void - { - $format = Format::BMP; - $this->assertInstanceOf(BmpEncoder::class, $format->encoder()); - } - - public function testEncoderTiff(): void - { - $format = Format::TIFF; - $this->assertInstanceOf(TiffEncoder::class, $format->encoder()); - } - - public function testEncoderJpep2000(): void - { - $format = Format::JP2; - $this->assertInstanceOf(Jpeg2000Encoder::class, $format->encoder()); - } - - public function testEncoderHeic(): void - { - $format = Format::HEIC; - $this->assertInstanceOf(HeicEncoder::class, $format->encoder()); - } - - public function testFileExtensionsJpeg(): void - { - $format = Format::JPEG; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(2, $extensions); - - $this->assertEquals(FileExtension::JPG, $format->fileExtension()); - } - - public function testFileExtensionsWebp(): void - { - $format = Format::WEBP; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(1, $extensions); - - $this->assertEquals(FileExtension::WEBP, $format->fileExtension()); - } - - public function testFileExtensionsGif(): void - { - $format = Format::GIF; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(1, $extensions); - - $this->assertEquals(FileExtension::GIF, $format->fileExtension()); - } - - public function testFileExtensionsPng(): void - { - $format = Format::PNG; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(1, $extensions); - - $this->assertEquals(FileExtension::PNG, $format->fileExtension()); - } - - public function testFileExtensionsAvif(): void - { - $format = Format::AVIF; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(1, $extensions); - - $this->assertEquals(FileExtension::AVIF, $format->fileExtension()); - } - - public function testFileExtensionsBmp(): void - { - $format = Format::BMP; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(1, $extensions); - - $this->assertEquals(FileExtension::BMP, $format->fileExtension()); - } - - public function testFileExtensionsTiff(): void - { - $format = Format::TIFF; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(2, $extensions); - - $this->assertEquals(FileExtension::TIF, $format->fileExtension()); - } - - public function testFileExtensionsJp2(): void - { - $format = Format::JP2; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(8, $extensions); - - $this->assertEquals(FileExtension::JP2, $format->fileExtension()); - } - - public function testFileExtensionsHeic(): void - { - $format = Format::HEIC; - $extensions = $format->fileExtensions(); - $this->assertIsArray($extensions); - $this->assertCount(2, $extensions); - - $this->assertEquals(FileExtension::HEIC, $format->fileExtension()); - } -} diff --git a/tests/Unit/Geometry/BezierTest.php b/tests/Unit/Geometry/BezierTest.php deleted file mode 100644 index 8eed7e91..00000000 --- a/tests/Unit/Geometry/BezierTest.php +++ /dev/null @@ -1,177 +0,0 @@ -assertInstanceOf(Bezier::class, $bezier); - $this->assertEquals(0, $bezier->count()); - } - - public function testCount(): void - { - $bezier = new Bezier([ - new Point(), - new Point(), - new Point(), - new Point() - ]); - $this->assertEquals(4, $bezier->count()); - } - - public function testArrayAccess(): void - { - $bezier = new Bezier([ - new Point(), - new Point(), - new Point(), - new Point() - ]); - $this->assertInstanceOf(Point::class, $bezier[0]); - $this->assertInstanceOf(Point::class, $bezier[1]); - $this->assertInstanceOf(Point::class, $bezier[2]); - $this->assertInstanceOf(Point::class, $bezier[3]); - } - - public function testAddPoint(): void - { - $bezier = new Bezier([ - new Point(), - new Point() - ]); - $this->assertEquals(2, $bezier->count()); - $result = $bezier->addPoint(new Point()); - $this->assertEquals(3, $bezier->count()); - $this->assertInstanceOf(Bezier::class, $result); - } - - public function testFirst(): void - { - $bezier = new Bezier([ - new Point(50, 45), - new Point(100, -49), - new Point(-100, 100), - new Point(200, 300), - ]); - $this->assertEquals(50, $bezier->first()->x()); - $this->assertEquals(45, $bezier->first()->y()); - } - - public function testFirstEmpty(): void - { - $bezier = new Bezier(); - $this->assertNull($bezier->first()); - } - - public function testSecond(): void - { - $bezier = new Bezier([ - new Point(50, 45), - new Point(100, -49), - new Point(-100, 100), - new Point(200, 300), - ]); - $this->assertEquals(100, $bezier->second()->x()); - $this->assertEquals(-49, $bezier->second()->y()); - } - - public function testSecondEmpty(): void - { - $bezier = new Bezier(); - $this->assertNull($bezier->second()); - } - - public function testThird(): void - { - $bezier = new Bezier([ - new Point(50, 45), - new Point(100, -49), - new Point(-100, 100), - new Point(200, 300), - ]); - $this->assertEquals(-100, $bezier->third()->x()); - $this->assertEquals(100, $bezier->third()->y()); - } - - public function testThirdEmpty(): void - { - $bezier = new Bezier(); - $this->assertNull($bezier->third()); - } - - public function testLast(): void - { - $bezier = new Bezier([ - new Point(50, 45), - new Point(100, -49), - new Point(-100, 100), - new Point(200, 300), - ]); - $this->assertEquals(200, $bezier->last()->x()); - $this->assertEquals(300, $bezier->last()->y()); - } - - public function testLastEmpty(): void - { - $bezier = new Bezier(); - $this->assertNull($bezier->last()); - } - - public function testOffsetExists(): void - { - $bezier = new Bezier(); - $this->assertFalse($bezier->offsetExists(0)); - $this->assertFalse($bezier->offsetExists(1)); - $bezier->addPoint(new Point(0, 0)); - $this->assertTrue($bezier->offsetExists(0)); - $this->assertFalse($bezier->offsetExists(1)); - } - - public function testOffsetSetUnset(): void - { - $bezier = new Bezier(); - $bezier->offsetSet(0, new Point()); - $bezier->offsetSet(2, new Point()); - $this->assertTrue($bezier->offsetExists(0)); - $this->assertFalse($bezier->offsetExists(1)); - $this->assertTrue($bezier->offsetExists(2)); - $bezier->offsetUnset(2); - $this->assertTrue($bezier->offsetExists(0)); - $this->assertFalse($bezier->offsetExists(1)); - $this->assertFalse($bezier->offsetExists(2)); - } - - public function testGetSetPivotPoint(): void - { - $bezier = new Bezier(); - $this->assertInstanceOf(Point::class, $bezier->pivot()); - $this->assertEquals(0, $bezier->pivot()->x()); - $this->assertEquals(0, $bezier->pivot()->y()); - $result = $bezier->setPivot(new Point(12, 34)); - $this->assertInstanceOf(Bezier::class, $result); - $this->assertEquals(12, $bezier->pivot()->x()); - $this->assertEquals(34, $bezier->pivot()->y()); - } - - public function testToArray(): void - { - $bezier = new Bezier([ - new Point(50, 50), - new Point(100, 50), - new Point(-50, -100), - new Point(50, 100), - ]); - $this->assertEquals([50, 50, 100, 50, -50, -100, 50, 100], $bezier->toArray()); - } -} diff --git a/tests/Unit/Geometry/CircleTest.php b/tests/Unit/Geometry/CircleTest.php deleted file mode 100644 index 15512025..00000000 --- a/tests/Unit/Geometry/CircleTest.php +++ /dev/null @@ -1,42 +0,0 @@ -assertInstanceOf(Circle::class, $circle); - $this->assertEquals(100, $circle->diameter()); - $this->assertInstanceOf(Point::class, $circle->pivot()); - } - - public function testSetGetDiameter(): void - { - $circle = new Circle(100, new Point(1, 2)); - $this->assertEquals(100, $circle->diameter()); - $result = $circle->setDiameter(200); - $this->assertInstanceOf(Circle::class, $result); - $this->assertEquals(200, $result->diameter()); - $this->assertEquals(200, $circle->diameter()); - } - - public function testSetGetRadius(): void - { - $circle = new Circle(100, new Point(1, 2)); - $this->assertEquals(50, $circle->radius()); - $result = $circle->setRadius(200); - $this->assertInstanceOf(Circle::class, $result); - $this->assertEquals(400, $result->diameter()); - $this->assertEquals(400, $circle->diameter()); - $this->assertEquals(200, $result->radius()); - $this->assertEquals(200, $circle->radius()); - } -} diff --git a/tests/Unit/Geometry/EllipseTest.php b/tests/Unit/Geometry/EllipseTest.php deleted file mode 100644 index 31e8c7bc..00000000 --- a/tests/Unit/Geometry/EllipseTest.php +++ /dev/null @@ -1,58 +0,0 @@ -assertInstanceOf(Ellipse::class, $ellipse); - $this->assertEquals(10, $ellipse->width()); - $this->assertEquals(20, $ellipse->height()); - } - - public function testPosition(): void - { - $ellipse = new Ellipse(10, 20, new Point(100, 200)); - $this->assertInstanceOf(Point::class, $ellipse->position()); - $this->assertEquals(100, $ellipse->position()->x()); - $this->assertEquals(200, $ellipse->position()->y()); - - $this->assertInstanceOf(Point::class, $ellipse->pivot()); - $this->assertEquals(100, $ellipse->pivot()->x()); - $this->assertEquals(200, $ellipse->pivot()->y()); - } - - public function testSetSize(): void - { - $ellipse = new Ellipse(10, 20, new Point(100, 200)); - $this->assertEquals(10, $ellipse->width()); - $this->assertEquals(20, $ellipse->height()); - $result = $ellipse->setSize(100, 200); - $this->assertInstanceOf(Ellipse::class, $result); - $this->assertEquals(100, $ellipse->width()); - $this->assertEquals(200, $ellipse->height()); - } - - public function testSetWidthHeight(): void - { - $ellipse = new Ellipse(10, 20, new Point(100, 200)); - $this->assertEquals(10, $ellipse->width()); - $this->assertEquals(20, $ellipse->height()); - $result = $ellipse->setWidth(100); - $this->assertInstanceOf(Ellipse::class, $result); - $this->assertEquals(100, $ellipse->width()); - $this->assertEquals(20, $ellipse->height()); - $result = $ellipse->setHeight(200); - $this->assertInstanceOf(Ellipse::class, $result); - $this->assertEquals(100, $ellipse->width()); - $this->assertEquals(200, $ellipse->height()); - } -} diff --git a/tests/Unit/Geometry/Factories/BezierFactoryTest.php b/tests/Unit/Geometry/Factories/BezierFactoryTest.php deleted file mode 100644 index a3e4ad30..00000000 --- a/tests/Unit/Geometry/Factories/BezierFactoryTest.php +++ /dev/null @@ -1,31 +0,0 @@ -background('f00'); - $bezier->border('ff0', 10); - $bezier->point(300, 260); - $bezier->point(150, 335); - $bezier->point(300, 410); - }); - - $bezier = $factory(); - $this->assertInstanceOf(Bezier::class, $bezier); - $this->assertTrue($bezier->hasBackgroundColor()); - $this->assertEquals('f00', $bezier->backgroundColor()); - $this->assertEquals('ff0', $bezier->borderColor()); - $this->assertEquals(10, $bezier->borderSize()); - $this->assertEquals(3, $bezier->count()); - } -} diff --git a/tests/Unit/Geometry/Factories/CircleFactoryTest.php b/tests/Unit/Geometry/Factories/CircleFactoryTest.php deleted file mode 100644 index 2dbc9524..00000000 --- a/tests/Unit/Geometry/Factories/CircleFactoryTest.php +++ /dev/null @@ -1,32 +0,0 @@ -background('fff'); - $circle->border('ccc', 10); - $circle->radius(100); - $circle->diameter(1000); - }); - - $circle = $factory(); - $this->assertInstanceOf(Ellipse::class, $circle); - $this->assertTrue($circle->hasBackgroundColor()); - $this->assertEquals('fff', $circle->backgroundColor()); - $this->assertEquals('ccc', $circle->borderColor()); - $this->assertEquals(10, $circle->borderSize()); - $this->assertEquals(1000, $circle->width()); - $this->assertEquals(1000, $circle->height()); - } -} diff --git a/tests/Unit/Geometry/Factories/DrawableTest.php b/tests/Unit/Geometry/Factories/DrawableTest.php deleted file mode 100644 index a0bbec77..00000000 --- a/tests/Unit/Geometry/Factories/DrawableTest.php +++ /dev/null @@ -1,47 +0,0 @@ -assertInstanceOf(BezierFactory::class, Drawable::bezier()); - } - - public function testCircle(): void - { - $this->assertInstanceOf(CircleFactory::class, Drawable::circle()); - } - - public function testEllipse(): void - { - $this->assertInstanceOf(EllipseFactory::class, Drawable::ellipse()); - } - - public function testLine(): void - { - $this->assertInstanceOf(LineFactory::class, Drawable::line()); - } - - public function testPolygon(): void - { - $this->assertInstanceOf(PolygonFactory::class, Drawable::polygon()); - } - - public function testRectangle(): void - { - $this->assertInstanceOf(RectangleFactory::class, Drawable::rectangle()); - } -} diff --git a/tests/Unit/Geometry/Factories/EllipseFactoryTest.php b/tests/Unit/Geometry/Factories/EllipseFactoryTest.php deleted file mode 100644 index e5e37c26..00000000 --- a/tests/Unit/Geometry/Factories/EllipseFactoryTest.php +++ /dev/null @@ -1,33 +0,0 @@ -background('fff'); - $ellipse->border('ccc', 10); - $ellipse->width(100); - $ellipse->height(200); - $ellipse->size(1000, 2000); - }); - - $ellipse = $factory(); - $this->assertInstanceOf(Ellipse::class, $ellipse); - $this->assertTrue($ellipse->hasBackgroundColor()); - $this->assertEquals('fff', $ellipse->backgroundColor()); - $this->assertEquals('ccc', $ellipse->borderColor()); - $this->assertEquals(10, $ellipse->borderSize()); - $this->assertEquals(1000, $ellipse->width()); - $this->assertEquals(2000, $ellipse->height()); - } -} diff --git a/tests/Unit/Geometry/Factories/LineFactoryTest.php b/tests/Unit/Geometry/Factories/LineFactoryTest.php deleted file mode 100644 index 6870fe2f..00000000 --- a/tests/Unit/Geometry/Factories/LineFactoryTest.php +++ /dev/null @@ -1,34 +0,0 @@ -color('fff'); - $line->background('fff'); - $line->border('fff', 10); - $line->width(10); - $line->from(100, 200); - $line->to(300, 400); - }); - - $line = $factory(); - $this->assertInstanceOf(Line::class, $line); - $this->assertTrue($line->hasBackgroundColor()); - $this->assertEquals('fff', $line->backgroundColor()); - $this->assertEquals(100, $line->start()->x()); - $this->assertEquals(200, $line->start()->y()); - $this->assertEquals(300, $line->end()->x()); - $this->assertEquals(400, $line->end()->y()); - $this->assertEquals(10, $line->width()); - } -} diff --git a/tests/Unit/Geometry/Factories/PolygonFactoryTest.php b/tests/Unit/Geometry/Factories/PolygonFactoryTest.php deleted file mode 100644 index ebc41f02..00000000 --- a/tests/Unit/Geometry/Factories/PolygonFactoryTest.php +++ /dev/null @@ -1,31 +0,0 @@ -background('fff'); - $polygon->border('ccc', 10); - $polygon->point(1, 2); - $polygon->point(3, 4); - $polygon->point(5, 6); - }); - - $polygon = $factory(); - $this->assertInstanceOf(Polygon::class, $polygon); - $this->assertTrue($polygon->hasBackgroundColor()); - $this->assertEquals('fff', $polygon->backgroundColor()); - $this->assertEquals('ccc', $polygon->borderColor()); - $this->assertEquals(10, $polygon->borderSize()); - $this->assertEquals(3, $polygon->count()); - } -} diff --git a/tests/Unit/Geometry/Factories/RectangleFactoryTest.php b/tests/Unit/Geometry/Factories/RectangleFactoryTest.php deleted file mode 100644 index 79f86959..00000000 --- a/tests/Unit/Geometry/Factories/RectangleFactoryTest.php +++ /dev/null @@ -1,33 +0,0 @@ -background('fff'); - $rectangle->border('ccc', 10); - $rectangle->width(100); - $rectangle->height(200); - $rectangle->size(1000, 2000); - }); - - $rectangle = $factory(); - $this->assertInstanceOf(Rectangle::class, $rectangle); - $this->assertTrue($rectangle->hasBackgroundColor()); - $this->assertEquals('fff', $rectangle->backgroundColor()); - $this->assertEquals('ccc', $rectangle->borderColor()); - $this->assertEquals(10, $rectangle->borderSize()); - $this->assertEquals(1000, $rectangle->width()); - $this->assertEquals(2000, $rectangle->height()); - } -} diff --git a/tests/Unit/Geometry/LineTest.php b/tests/Unit/Geometry/LineTest.php deleted file mode 100644 index c0153a98..00000000 --- a/tests/Unit/Geometry/LineTest.php +++ /dev/null @@ -1,78 +0,0 @@ -assertInstanceOf(Line::class, $line); - } - - public function testPosition(): void - { - $line = new Line(new Point(1, 2), new Point(3, 4), 10); - $this->assertEquals(1, $line->position()->x()); - $this->assertEquals(2, $line->position()->y()); - } - - public function testSetGetStart(): void - { - $line = new Line(new Point(1, 2), new Point(3, 4), 10); - $this->assertEquals(1, $line->start()->x()); - $this->assertEquals(2, $line->start()->y()); - $result = $line->setStart(new Point(10, 20)); - $this->assertInstanceOf(Line::class, $result); - $this->assertEquals(10, $line->start()->x()); - $this->assertEquals(20, $line->start()->y()); - } - - public function testSetGetEnd(): void - { - $line = new Line(new Point(1, 2), new Point(3, 4), 10); - $this->assertEquals(3, $line->end()->x()); - $this->assertEquals(4, $line->end()->y()); - $result = $line->setEnd(new Point(30, 40)); - $this->assertInstanceOf(Line::class, $result); - $this->assertEquals(30, $line->end()->x()); - $this->assertEquals(40, $line->end()->y()); - } - - public function setFrom(): void - { - $line = new Line(new Point(1, 2), new Point(3, 4), 10); - $this->assertEquals(1, $line->start()->x()); - $this->assertEquals(2, $line->start()->y()); - $result = $line->from(10, 20); - $this->assertInstanceOf(Line::class, $result); - $this->assertEquals(10, $line->start()->x()); - $this->assertEquals(20, $line->start()->y()); - } - - public function setTo(): void - { - $line = new Line(new Point(1, 2), new Point(3, 4), 10); - $this->assertEquals(3, $line->end()->x()); - $this->assertEquals(4, $line->end()->y()); - $result = $line->to(30, 40); - $this->assertInstanceOf(Line::class, $result); - $this->assertEquals(30, $line->end()->x()); - $this->assertEquals(40, $line->end()->y()); - } - - public function testSetGetWidth(): void - { - $line = new Line(new Point(1, 2), new Point(3, 4), 10); - $this->assertEquals(10, $line->width()); - $result = $line->setWidth(20); - $this->assertInstanceOf(Line::class, $result); - $this->assertEquals(20, $line->width()); - } -} diff --git a/tests/Unit/Geometry/PixelTest.php b/tests/Unit/Geometry/PixelTest.php deleted file mode 100644 index 5115dde8..00000000 --- a/tests/Unit/Geometry/PixelTest.php +++ /dev/null @@ -1,24 +0,0 @@ -setBackgroundColor($color); - $this->assertInstanceOf(ColorInterface::class, $pixel->backgroundColor()); - $this->assertInstanceOf(Pixel::class, $result); - } -} diff --git a/tests/Unit/Geometry/PointTest.php b/tests/Unit/Geometry/PointTest.php deleted file mode 100644 index 002ca0a6..00000000 --- a/tests/Unit/Geometry/PointTest.php +++ /dev/null @@ -1,91 +0,0 @@ -assertInstanceOf(Point::class, $point); - $this->assertEquals(0, $point->x()); - $this->assertEquals(0, $point->y()); - } - - public function testConstructorWithParameters(): void - { - $point = new Point(40, 50); - $this->assertInstanceOf(Point::class, $point); - $this->assertEquals(40, $point->x()); - $this->assertEquals(50, $point->y()); - } - - public function testGetSetX(): void - { - $point = new Point(0, 0); - $point->setX(100); - $this->assertEquals(100, $point->x()); - $this->assertEquals(0, $point->y()); - } - - public function testGetSetY(): void - { - $point = new Point(0, 0); - $point->setY(100); - $this->assertEquals(0, $point->x()); - $this->assertEquals(100, $point->y()); - } - - public function testmoveX(): void - { - $point = new Point(50, 50); - $point->moveX(100); - $this->assertEquals(150, $point->x()); - $this->assertEquals(50, $point->y()); - } - - public function testmoveY(): void - { - $point = new Point(50, 50); - $point->moveY(100); - $this->assertEquals(50, $point->x()); - $this->assertEquals(150, $point->y()); - } - - public function testSetPosition(): void - { - $point = new Point(0, 0); - $point->setPosition(100, 200); - $this->assertEquals(100, $point->x()); - $this->assertEquals(200, $point->y()); - } - - public function testRotate(): void - { - $point = new Point(30, 0); - $point->rotate(90, new Point(0, 0)); - $this->assertEquals(0, $point->x()); - $this->assertEquals(30, $point->y()); - - $point->rotate(90, new Point(0, 0)); - $this->assertEquals(-30, $point->x()); - $this->assertEquals(0, $point->y()); - - $point = new Point(300, 200); - $point->rotate(90, new Point(0, 0)); - $this->assertEquals(-200, $point->x()); - $this->assertEquals(300, $point->y()); - - $point = new Point(0, 74); - $point->rotate(45, new Point(0, 0)); - $this->assertEquals(-52, $point->x()); - $this->assertEquals(52, $point->y()); - } -} diff --git a/tests/Unit/Geometry/PolygonTest.php b/tests/Unit/Geometry/PolygonTest.php deleted file mode 100644 index 73e5890b..00000000 --- a/tests/Unit/Geometry/PolygonTest.php +++ /dev/null @@ -1,447 +0,0 @@ -assertInstanceOf(Polygon::class, $poly); - $this->assertEquals(0, $poly->count()); - } - - public function testCount(): void - { - $poly = new Polygon([new Point(), new Point()]); - $this->assertEquals(2, $poly->count()); - } - - public function testArrayAccess(): void - { - $poly = new Polygon([new Point(), new Point()]); - $this->assertInstanceOf(Point::class, $poly[0]); - $this->assertInstanceOf(Point::class, $poly[1]); - } - - public function testAddPoint(): void - { - $poly = new Polygon([new Point(), new Point()]); - $this->assertEquals(2, $poly->count()); - $result = $poly->addPoint(new Point()); - $this->assertEquals(3, $poly->count()); - $this->assertInstanceOf(Polygon::class, $result); - } - - public function testGetCenterPoint(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(20, 0), - new Point(20, -20), - new Point(0, -20), - ]); - - $result = $poly->centerPoint(); - $this->assertEquals(10, $result->x()); - $this->assertEquals(-10, $result->y()); - - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(0, 0)); - - $result = $poly->centerPoint(); - $this->assertEquals(150, $result->x()); - $this->assertEquals(-100, $result->y()); - } - - public function testGetWidth(): void - { - $poly = new Polygon([ - new Point(12, 45), - new Point(-23, -49), - new Point(3, 566), - ]); - - $this->assertEquals($poly->width(), 35); - } - - public function testGetHeight(): void - { - $poly = new Polygon([ - new Point(12, 45), - new Point(-23, -49), - new Point(3, 566), - ]); - - $this->assertEquals(615, $poly->height()); - - $poly = new Polygon([ - new Point(250, 207), - new Point(473, 207), - new Point(473, 250), - new Point(250, 250), - ], new Point(250, 250)); - - $this->assertEquals(43, $poly->height()); - } - - public function testFirst(): void - { - $poly = new Polygon([ - new Point(12, 45), - new Point(-23, -49), - new Point(3, 566), - ]); - - $this->assertEquals(12, $poly->first()->x()); - $this->assertEquals(45, $poly->first()->y()); - } - - public function testFirstEmpty(): void - { - $poly = new Polygon(); - $this->assertNull($poly->first()); - } - - public function testLast(): void - { - $poly = new Polygon([ - new Point(12, 45), - new Point(-23, -49), - new Point(3, 566), - ]); - - $this->assertEquals(3, $poly->last()->x()); - $this->assertEquals(566, $poly->last()->y()); - } - - public function testLastEmpty(): void - { - $poly = new Polygon(); - $this->assertNull($poly->last()); - } - - public function testOffsetExists(): void - { - $poly = new Polygon(); - $this->assertFalse($poly->offsetExists(0)); - $this->assertFalse($poly->offsetExists(1)); - $poly->addPoint(new Point(0, 0)); - $this->assertTrue($poly->offsetExists(0)); - $this->assertFalse($poly->offsetExists(1)); - } - - public function testOffsetSetUnset(): void - { - $poly = new Polygon(); - $poly->offsetSet(0, new Point()); - $poly->offsetSet(2, new Point()); - $this->assertTrue($poly->offsetExists(0)); - $this->assertFalse($poly->offsetExists(1)); - $this->assertTrue($poly->offsetExists(2)); - $poly->offsetUnset(2); - $this->assertTrue($poly->offsetExists(0)); - $this->assertFalse($poly->offsetExists(1)); - $this->assertFalse($poly->offsetExists(2)); - } - - public function testGetSetPivotPoint(): void - { - $poly = new Polygon(); - $this->assertInstanceOf(Point::class, $poly->pivot()); - $this->assertEquals(0, $poly->pivot()->x()); - $this->assertEquals(0, $poly->pivot()->y()); - $result = $poly->setPivot(new Point(12, 34)); - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(12, $poly->pivot()->x()); - $this->assertEquals(34, $poly->pivot()->y()); - } - - public function testGetMostLeftPoint(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(-32, -200), - ], new Point(0, 0)); - - $result = $poly->mostLeftPoint(); - $this->assertEquals(-32, $result->x()); - $this->assertEquals(-200, $result->y()); - } - - public function testGetMostRightPoint(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(350, 0), - new Point(300, -200), - new Point(-32, -200), - ], new Point(0, 0)); - - $result = $poly->mostRightPoint(); - $this->assertEquals(350, $result->x()); - $this->assertEquals(0, $result->y()); - } - - public function testGetMostTopPoint(): void - { - $poly = new Polygon([ - new Point(0, 100), - new Point(350, 0), - new Point(300, -200), - new Point(-32, 200), - ], new Point(0, 0)); - - $result = $poly->mostTopPoint(); - $this->assertEquals(-32, $result->x()); - $this->assertEquals(200, $result->y()); - } - - public function testGetMostBottomPoint(): void - { - $poly = new Polygon([ - new Point(0, 100), - new Point(350, 0), - new Point(300, -200), - new Point(-32, 200), - ], new Point(0, 0)); - - $result = $poly->mostBottomPoint(); - $this->assertEquals(300, $result->x()); - $this->assertEquals(-200, $result->y()); - } - - public function testAlignCenter(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(0, 0)); - - $result = $poly->align('center'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-150, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(150, $result[1]->x()); - $this->assertEquals(0, $result[1]->y()); - $this->assertEquals(150, $result[2]->x()); - $this->assertEquals(-200, $result[2]->y()); - $this->assertEquals(-150, $result[3]->x()); - $this->assertEquals(-200, $result[3]->y()); - - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(-1000, -1000)); - - $result = $poly->align('center'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-1150, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(-850, $result[1]->x()); - $this->assertEquals(0, $result[1]->y()); - $this->assertEquals(-850, $result[2]->x()); - $this->assertEquals(-200, $result[2]->y()); - $this->assertEquals(-1150, $result[3]->x()); - $this->assertEquals(-200, $result[3]->y()); - } - - public function testAlignLeft(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(100, 100)); - - $result = $poly->align('left'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(100, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(400, $result[1]->x()); - $this->assertEquals(0, $result[1]->y()); - $this->assertEquals(400, $result[2]->x()); - $this->assertEquals(-200, $result[2]->y()); - $this->assertEquals(100, $result[3]->x()); - $this->assertEquals(-200, $result[3]->y()); - - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(-1000, -1000)); - - $result = $poly->align('left'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-1000, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(-700, $result[1]->x()); - $this->assertEquals(0, $result[1]->y()); - $this->assertEquals(-700, $result[2]->x()); - $this->assertEquals(-200, $result[2]->y()); - $this->assertEquals(-1000, $result[3]->x()); - $this->assertEquals(-200, $result[3]->y()); - } - - public function testAlignRight(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(100, 100)); - - $result = $poly->align('right'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-200, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(100, $result[1]->x()); - $this->assertEquals(0, $result[1]->y()); - $this->assertEquals(100, $result[2]->x()); - $this->assertEquals(-200, $result[2]->y()); - $this->assertEquals(-200, $result[3]->x()); - $this->assertEquals(-200, $result[3]->y()); - - $poly = new Polygon([ - new Point(0, 0), - new Point(300, 0), - new Point(300, -200), - new Point(0, -200), - ], new Point(-1000, -1000)); - - $result = $poly->align('right'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-1300, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(-1000, $result[1]->x()); - $this->assertEquals(0, $result[1]->y()); - $this->assertEquals(-1000, $result[2]->x()); - $this->assertEquals(-200, $result[2]->y()); - $this->assertEquals(-1300, $result[3]->x()); - $this->assertEquals(-200, $result[3]->y()); - } - - public function testValignMiddle(): void - { - $poly = new Polygon([ - new Point(-21, -22), - new Point(91, -135), - new Point(113, -113), - new Point(0, 0), - ], new Point(250, 250)); - - $result = $poly->valign('middle'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-21, $result[0]->x()); - $this->assertEquals(296, $result[0]->y()); - $this->assertEquals(91, $result[1]->x()); - $this->assertEquals(183, $result[1]->y()); - $this->assertEquals(113, $result[2]->x()); - $this->assertEquals(205, $result[2]->y()); - $this->assertEquals(0, $result[3]->x()); - $this->assertEquals(318, $result[3]->y()); - } - - public function testValignTop(): void - { - $poly = new Polygon([ - new Point(-21, -22), - new Point(91, -135), - new Point(113, -113), - new Point(0, 0), - ], new Point(250, 250)); - - $result = $poly->valign('top'); - - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(-21, $result[0]->x()); - $this->assertEquals(363, $result[0]->y()); - $this->assertEquals(91, $result[1]->x()); - $this->assertEquals(250, $result[1]->y()); - $this->assertEquals(113, $result[2]->x()); - $this->assertEquals(272, $result[2]->y()); - $this->assertEquals(0, $result[3]->x()); - $this->assertEquals(385, $result[3]->y()); - } - - public function testMovePoints(): void - { - $poly = new Polygon([ - new Point(10, 20), - new Point(30, 40) - ]); - - $result = $poly->movePointsX(100); - $this->assertEquals(110, $result[0]->x()); - $this->assertEquals(20, $result[0]->y()); - $this->assertEquals(130, $result[1]->x()); - $this->assertEquals(40, $result[1]->y()); - - $result = $poly->movePointsY(200); - $this->assertEquals(110, $result[0]->x()); - $this->assertEquals(220, $result[0]->y()); - $this->assertEquals(130, $result[1]->x()); - $this->assertEquals(240, $result[1]->y()); - } - - public function testRotate(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(50, 0), - new Point(50, -50), - new Point(0, -50), - ]); - - $result = $poly->rotate(45); - $this->assertInstanceOf(Polygon::class, $result); - $this->assertEquals(0, $result[0]->x()); - $this->assertEquals(0, $result[0]->y()); - $this->assertEquals(35, $result[1]->x()); - $this->assertEquals(35, $result[1]->y()); - $this->assertEquals(70, $result[2]->x()); - $this->assertEquals(0, $result[2]->y()); - $this->assertEquals(35, $result[3]->x()); - $this->assertEquals(-35, $result[3]->y()); - } - - public function testToArray(): void - { - $poly = new Polygon([ - new Point(0, 0), - new Point(50, 0), - new Point(50, -50), - new Point(0, -50), - ]); - - $this->assertEquals([0, 0, 50, 0, 50, -50, 0, -50], $poly->toArray()); - } -} diff --git a/tests/Unit/Geometry/RectangleResizerTest.php b/tests/Unit/Geometry/RectangleResizerTest.php deleted file mode 100644 index f5046d1b..00000000 --- a/tests/Unit/Geometry/RectangleResizerTest.php +++ /dev/null @@ -1,459 +0,0 @@ -assertInstanceOf(RectangleResizer::class, $resizer); - - $resizer = RectangleResizer::to(height: 100); - $this->assertInstanceOf(RectangleResizer::class, $resizer); - - $resizer = RectangleResizer::to(100); - $this->assertInstanceOf(RectangleResizer::class, $resizer); - - $resizer = RectangleResizer::to(100, 100); - $this->assertInstanceOf(RectangleResizer::class, $resizer); - } - - public function testToWidth(): void - { - $resizer = new RectangleResizer(); - $result = $resizer->toWidth(100); - $this->assertInstanceOf(RectangleResizer::class, $result); - } - - public function testToHeight(): void - { - $resizer = new RectangleResizer(); - $result = $resizer->toHeight(100); - $this->assertInstanceOf(RectangleResizer::class, $result); - } - - public function testToSize(): void - { - $resizer = new RectangleResizer(); - $resizer = $resizer->toSize(new Rectangle(200, 100)); - $this->assertInstanceOf(RectangleResizer::class, $resizer); - } - - public function testResize(): void - { - $size = new Rectangle(300, 200); - $resizer = new RectangleResizer(); - $resizer->toWidth(150); - $result = $resizer->resize($size); - $this->assertEquals(150, $result->width()); - $this->assertEquals(200, $result->height()); - - $size = new Rectangle(300, 200); - $resizer = new RectangleResizer(); - $resizer->toWidth(20); - $resizer->toHeight(10); - $result = $resizer->resize($size); - $this->assertEquals(20, $result->width()); - $this->assertEquals(10, $result->height()); - - $size = new Rectangle(300, 200); - $resizer = new RectangleResizer(width: 150); - $result = $resizer->resize($size); - $this->assertEquals(150, $result->width()); - $this->assertEquals(200, $result->height()); - - $size = new Rectangle(300, 200); - $resizer = new RectangleResizer(height: 10, width: 20); - $result = $resizer->resize($size); - $this->assertEquals(20, $result->width()); - $this->assertEquals(10, $result->height()); - } - - public function testResizeDown(): void - { - // 800x600 > 1000x2000 = 800x600 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(2000); - $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - - // 800x600 > 400x1000 = 400x600 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $resizer->toHeight(1000); - $result = $resizer->resizeDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(600, $result->height()); - - // 800x600 > 1000x400 = 800x400 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(400); - $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(400, $result->height()); - - // 800x600 > 400x300 = 400x300 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $resizer->toHeight(300); - $result = $resizer->resizeDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - - // 800x600 > 1000xnull = 800x600 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - - // 800x600 > nullx1000 = 800x600 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toHeight(1000); - $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - } - - public function testScale(): void - { - // 800x600 > 1000x2000 = 1000x750 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(2000); - $result = $resizer->scale($size); - $this->assertEquals(1000, $result->width()); - $this->assertEquals(750, $result->height()); - - // 800x600 > 2000x1000 = 1333x1000 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(2000); - $resizer->toHeight(1000); - $result = $resizer->scale($size); - $this->assertEquals(1333, $result->width()); - $this->assertEquals(1000, $result->height()); - - // // 800x600 > nullx3000 = 4000x3000 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toHeight(3000); - $result = $resizer->scale($size); - $this->assertEquals(4000, $result->width()); - $this->assertEquals(3000, $result->height()); - - // // 800x600 > 8000xnull = 8000x6000 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(8000); - $result = $resizer->scale($size); - $this->assertEquals(8000, $result->width()); - $this->assertEquals(6000, $result->height()); - - // // 800x600 > 100x400 = 100x75 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(100); - $resizer->toHeight(400); - $result = $resizer->scale($size); - $this->assertEquals(100, $result->width()); - $this->assertEquals(75, $result->height()); - - // // 800x600 > 400x100 = 133x100 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $resizer->toHeight(100); - $result = $resizer->scale($size); - $this->assertEquals(133, $result->width()); - $this->assertEquals(100, $result->height()); - - // // 800x600 > nullx300 = 400x300 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toHeight(300); - $result = $resizer->scale($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - - // // 800x600 > 80xnull = 80x60 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(80); - $result = $resizer->scale($size); - $this->assertEquals(80, $result->width()); - $this->assertEquals(60, $result->height()); - - // // 640x480 > 225xnull = 225x169 - $size = new Rectangle(640, 480); - $resizer = new RectangleResizer(); - $resizer->toWidth(225); - $result = $resizer->scale($size); - $this->assertEquals(225, $result->width()); - $this->assertEquals(169, $result->height()); - - // // 640x480 > 223xnull = 223x167 - $size = new Rectangle(640, 480); - $resizer = new RectangleResizer(); - $resizer->toWidth(223); - $result = $resizer->scale($size); - $this->assertEquals(223, $result->width()); - $this->assertEquals(167, $result->height()); - - // // 600x800 > 300x300 = 225x300 - $size = new Rectangle(600, 800); - $resizer = new RectangleResizer(); - $resizer->toWidth(300); - $resizer->toHeight(300); - $result = $resizer->scale($size); - $this->assertEquals(225, $result->width()); - $this->assertEquals(300, $result->height()); - - // // 800x600 > 400x10 = 13x10 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $resizer->toHeight(10); - $result = $resizer->scale($size); - $this->assertEquals(13, $result->width()); - $this->assertEquals(10, $result->height()); - - // // 800x600 > 1000x1200 = 1000x750 - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(1200); - $result = $resizer->scale($size); - $this->assertEquals(1000, $result->width()); - $this->assertEquals(750, $result->height()); - - $size = new Rectangle(12000, 12); - $resizer = new RectangleResizer(); - $resizer->toWidth(4000); - $resizer->toHeight(3000); - $result = $resizer->scale($size); - $this->assertEquals(4000, $result->width()); - $this->assertEquals(4, $result->height()); - - $size = new Rectangle(12, 12000); - $resizer = new RectangleResizer(); - $resizer->toWidth(4000); - $resizer->toHeight(3000); - $result = $resizer->scale($size); - $this->assertEquals(3, $result->width()); - $this->assertEquals(3000, $result->height()); - - $size = new Rectangle(12000, 6000); - $resizer = new RectangleResizer(); - $resizer->toWidth(4000); - $resizer->toHeight(3000); - $result = $resizer->scale($size); - $this->assertEquals(4000, $result->width()); - $this->assertEquals(2000, $result->height()); - - $size = new Rectangle(3, 3000); - $resizer = new RectangleResizer(); - $resizer->toHeight(300); - $result = $resizer->scale($size); - $this->assertEquals(1, $result->width()); - $this->assertEquals(300, $result->height()); - } - - public function testScaleDown(): void - { - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(2000); - $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(600); - $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $resizer->toHeight(300); - $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $resizer->toHeight(1000); - $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toHeight(300); - $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(1000); - $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toHeight(1000); - $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(100); - $result = $resizer->scaleDown($size); - $this->assertEquals(100, $result->width()); - $this->assertEquals(75, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(300); - $resizer->toHeight(200); - $result = $resizer->scaleDown($size); - $this->assertEquals(267, $result->width()); - $this->assertEquals(200, $result->height()); - - $size = new Rectangle(600, 800); - $resizer = new RectangleResizer(); - $resizer->toWidth(300); - $resizer->toHeight(300); - $result = $resizer->scaleDown($size); - $this->assertEquals(225, $result->width()); - $this->assertEquals(300, $result->height()); - - $size = new Rectangle(800, 600); - $resizer = new RectangleResizer(); - $resizer->toWidth(400); - $resizer->toHeight(10); - $result = $resizer->scaleDown($size); - $this->assertEquals(13, $result->width()); - $this->assertEquals(10, $result->height()); - - $size = new Rectangle(3, 3000); - $resizer = new RectangleResizer(); - $resizer->toHeight(300); - $result = $resizer->scale($size); - $this->assertEquals(1, $result->width()); - $this->assertEquals(300, $result->height()); - } - - #[DataProvider('coverDataProvider')] - public function testCover($origin, $target, $result): void - { - $resizer = new RectangleResizer(); - $resizer->toSize($target); - $resized = $resizer->cover($origin); - $this->assertEquals($result->width(), $resized->width()); - $this->assertEquals($result->height(), $resized->height()); - } - - public static function coverDataProvider(): array - { - return [ - [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(133, 100)], - [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(200, 150)], - [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(267, 200)], - [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(2000, 1500)], - [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(2667, 2000)], - [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)], - [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(160, 120)], - [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(100, 133)], - [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(800, 800)], - ]; - } - - #[DataProvider('containDataProvider')] - public function testContain($origin, $target, $result): void - { - $resizer = new RectangleResizer(); - $resizer->toSize($target); - $resized = $resizer->contain($origin); - $this->assertEquals($result->width(), $resized->width()); - $this->assertEquals($result->height(), $resized->height()); - } - - public static function containDataProvider(): array - { - return [ - [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(100, 75)], - [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(133, 100)], - [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(100, 75)], - [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(13, 10)], - [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(10, 8)], - [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)], - [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(120, 90)], - [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(75, 100)], - [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(600, 600)], - ]; - } - - #[DataProvider('cropDataProvider')] - public function testCrop($origin, $target, $position, $result): void - { - $resizer = new RectangleResizer(); - $resizer->toSize($target); - $resized = $resizer->crop($origin, $position); - $this->assertEquals($result->width(), $resized->width()); - $this->assertEquals($result->height(), $resized->height()); - $this->assertEquals($result->pivot()->x(), $resized->pivot()->x()); - $this->assertEquals($result->pivot()->y(), $resized->pivot()->y()); - } - - public static function cropDataProvider(): array - { - return [ - [new Rectangle(800, 600), new Rectangle(100, 100), 'center', new Rectangle(100, 100, new Point(350, 250))], - [new Rectangle(800, 600), new Rectangle(200, 100), 'center', new Rectangle(200, 100, new Point(300, 250))], - [new Rectangle(800, 600), new Rectangle(100, 200), 'center', new Rectangle(100, 200, new Point(350, 200))], - [new Rectangle(800, 600), new Rectangle(2000, 10), 'center', new Rectangle(2000, 10, new Point(-600, 295))], - [new Rectangle(800, 600), new Rectangle(10, 2000), 'center', new Rectangle(10, 2000, new Point(395, -700))], - [new Rectangle(800, 600), new Rectangle(800, 600), 'center', new Rectangle(800, 600, new Point(0, 0))], - [new Rectangle(400, 300), new Rectangle(120, 120), 'center', new Rectangle(120, 120, new Point(140, 90))], - [new Rectangle(600, 800), new Rectangle(100, 100), 'center', new Rectangle(100, 100, new Point(250, 350))], - ]; - } -} diff --git a/tests/Unit/Geometry/RectangleTest.php b/tests/Unit/Geometry/RectangleTest.php deleted file mode 100644 index ff61fdfe..00000000 --- a/tests/Unit/Geometry/RectangleTest.php +++ /dev/null @@ -1,326 +0,0 @@ -assertEquals(0, $rectangle[0]->x()); - $this->assertEquals(0, $rectangle[0]->y()); - $this->assertEquals(300, $rectangle[1]->x()); - $this->assertEquals(0, $rectangle[1]->y()); - $this->assertEquals(300, $rectangle[2]->x()); - $this->assertEquals(-200, $rectangle[2]->y()); - $this->assertEquals(0, $rectangle[3]->x()); - $this->assertEquals(-200, $rectangle[3]->y()); - $this->assertEquals(300, $rectangle->width()); - $this->assertEquals(200, $rectangle->height()); - } - - public function testSetSize(): void - { - $rectangle = new Rectangle(300, 200); - $rectangle->setSize(12, 34); - $this->assertEquals(12, $rectangle->width()); - $this->assertEquals(34, $rectangle->height()); - } - - public function testSetWidth(): void - { - $rectangle = new Rectangle(300, 200); - $this->assertEquals(300, $rectangle->width()); - $rectangle->setWidth(400); - $this->assertEquals(400, $rectangle->width()); - } - - public function testSetHeight(): void - { - $rectangle = new Rectangle(300, 200); - $this->assertEquals(200, $rectangle->height()); - $rectangle->setHeight(800); - $this->assertEquals(800, $rectangle->height()); - } - - public function testGetAspectRatio(): void - { - $size = new Rectangle(800, 600); - $this->assertEquals(1.333, round($size->aspectRatio(), 3)); - - $size = new Rectangle(100, 100); - $this->assertEquals(1, $size->aspectRatio()); - - $size = new Rectangle(1920, 1080); - $this->assertEquals(1.778, round($size->aspectRatio(), 3)); - } - - public function testFitsInto(): void - { - $box = new Rectangle(800, 600); - $fits = $box->fitsInto(new Rectangle(100, 100)); - $this->assertFalse($fits); - - $box = new Rectangle(800, 600); - $fits = $box->fitsInto(new Rectangle(1000, 100)); - $this->assertFalse($fits); - - $box = new Rectangle(800, 600); - $fits = $box->fitsInto(new Rectangle(100, 1000)); - $this->assertFalse($fits); - - $box = new Rectangle(800, 600); - $fits = $box->fitsInto(new Rectangle(800, 600)); - $this->assertTrue($fits); - - $box = new Rectangle(800, 600); - $fits = $box->fitsInto(new Rectangle(1000, 1000)); - $this->assertTrue($fits); - - $box = new Rectangle(100, 100); - $fits = $box->fitsInto(new Rectangle(800, 600)); - $this->assertTrue($fits); - - $box = new Rectangle(100, 100); - $fits = $box->fitsInto(new Rectangle(80, 60)); - $this->assertFalse($fits); - } - - public function testIsLandscape(): void - { - $box = new Rectangle(100, 100); - $this->assertFalse($box->isLandscape()); - - $box = new Rectangle(100, 200); - $this->assertFalse($box->isLandscape()); - - $box = new Rectangle(300, 200); - $this->assertTrue($box->isLandscape()); - } - - public function testIsPortrait(): void - { - $box = new Rectangle(100, 100); - $this->assertFalse($box->isPortrait()); - - $box = new Rectangle(200, 100); - $this->assertFalse($box->isPortrait()); - - $box = new Rectangle(200, 300); - $this->assertTrue($box->isPortrait()); - } - - public function testSetGetPivot(): void - { - $box = new Rectangle(800, 600); - $pivot = $box->pivot(); - $this->assertInstanceOf(Point::class, $pivot); - $this->assertEquals(0, $pivot->x()); - $result = $box->setPivot(new Point(10, 0)); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(10, $box->pivot()->x()); - } - - public function testAlignPivot(): void - { - $box = new Rectangle(640, 480); - $this->assertEquals(0, $box->pivot()->x()); - $this->assertEquals(0, $box->pivot()->y()); - - $box->movePivot('top-left', 3, 3); - $this->assertEquals(3, $box->pivot()->x()); - $this->assertEquals(3, $box->pivot()->y()); - - $box->movePivot('top', 3, 3); - $this->assertEquals(323, $box->pivot()->x()); - $this->assertEquals(3, $box->pivot()->y()); - - $box->movePivot('top-right', 3, 3); - $this->assertEquals(637, $box->pivot()->x()); - $this->assertEquals(3, $box->pivot()->y()); - - $box->movePivot('left', 3, 3); - $this->assertEquals(3, $box->pivot()->x()); - $this->assertEquals(243, $box->pivot()->y()); - - $box->movePivot('center', 3, 3); - $this->assertEquals(323, $box->pivot()->x()); - $this->assertEquals(243, $box->pivot()->y()); - - $box->movePivot('right', 3, 3); - $this->assertEquals(637, $box->pivot()->x()); - $this->assertEquals(243, $box->pivot()->y()); - - $box->movePivot('bottom-left', 3, 3); - $this->assertEquals(3, $box->pivot()->x()); - $this->assertEquals(477, $box->pivot()->y()); - - $box->movePivot('bottom', 3, 3); - $this->assertEquals(323, $box->pivot()->x()); - $this->assertEquals(477, $box->pivot()->y()); - - $result = $box->movePivot('bottom-right', 3, 3); - $this->assertEquals(637, $box->pivot()->x()); - $this->assertEquals(477, $box->pivot()->y()); - - $this->assertInstanceOf(Rectangle::class, $result); - } - - public function testAlignPivotTo(): void - { - $container = new Rectangle(800, 600); - $size = new Rectangle(200, 100); - $size->alignPivotTo($container, 'center'); - $this->assertEquals(300, $size->pivot()->x()); - $this->assertEquals(250, $size->pivot()->y()); - - $container = new Rectangle(800, 600); - $size = new Rectangle(100, 100); - $size->alignPivotTo($container, 'center'); - $this->assertEquals(350, $size->pivot()->x()); - $this->assertEquals(250, $size->pivot()->y()); - - $container = new Rectangle(800, 600); - $size = new Rectangle(800, 600); - $size->alignPivotTo($container, 'center'); - $this->assertEquals(0, $size->pivot()->x()); - $this->assertEquals(0, $size->pivot()->y()); - - $container = new Rectangle(100, 100); - $size = new Rectangle(800, 600); - $size->alignPivotTo($container, 'center'); - $this->assertEquals(-350, $size->pivot()->x()); - $this->assertEquals(-250, $size->pivot()->y()); - - $container = new Rectangle(100, 100); - $size = new Rectangle(800, 600); - $size->alignPivotTo($container, 'bottom-right'); - $this->assertEquals(-700, $size->pivot()->x()); - $this->assertEquals(-500, $size->pivot()->y()); - } - - public function testgetRelativePositionTo(): void - { - $container = new Rectangle(800, 600); - $input = new Rectangle(200, 100); - $container->movePivot('top-left'); - $input->movePivot('top-left'); - $pos = $container->relativePositionTo($input); - $this->assertEquals(0, $pos->x()); - $this->assertEquals(0, $pos->y()); - - $container = new Rectangle(800, 600); - $input = new Rectangle(200, 100); - $container->movePivot('center'); - $input->movePivot('top-left'); - $pos = $container->relativePositionTo($input); - $this->assertEquals(400, $pos->x()); - $this->assertEquals(300, $pos->y()); - - $container = new Rectangle(800, 600); - $input = new Rectangle(200, 100); - $container->movePivot('bottom-right'); - $input->movePivot('top-right'); - $pos = $container->relativePositionTo($input); - $this->assertEquals(600, $pos->x()); - $this->assertEquals(600, $pos->y()); - - $container = new Rectangle(800, 600); - $input = new Rectangle(200, 100); - $container->movePivot('center'); - $input->movePivot('center'); - $pos = $container->relativePositionTo($input); - $this->assertEquals(300, $pos->x()); - $this->assertEquals(250, $pos->y()); - - $container = new Rectangle(100, 200); - $input = new Rectangle(100, 100); - $container->movePivot('center'); - $input->movePivot('center'); - $pos = $container->relativePositionTo($input); - $this->assertEquals(0, $pos->x()); - $this->assertEquals(50, $pos->y()); - } - - public function testTopLeftPoint(): void - { - $rectangle = new Rectangle(800, 600); - $this->assertInstanceOf(PointInterface::class, $rectangle->topLeftPoint()); - } - - public function testBottomRightPoint(): void - { - $rectangle = new Rectangle(800, 600); - $this->assertInstanceOf(PointInterface::class, $rectangle->bottomRightPoint()); - } - - public function testResize(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->resize(300, 200); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(300, $result->width()); - $this->assertEquals(200, $result->height()); - } - - public function testResizeDown(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->resizeDown(3000, 200); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(800, $result->width()); - $this->assertEquals(200, $result->height()); - } - - public function testScale(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->scale(height: 1200); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(800 * 2, $result->width()); - $this->assertEquals(600 * 2, $result->height()); - } - - public function testScaleDown(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->scaleDown(height: 1200); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - } - - public function testCover(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->cover(400, 100); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); - } - - public function testContain(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->contain(1600, 1200); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(1600, $result->width()); - $this->assertEquals(1200, $result->height()); - } - - public function testContainMax(): void - { - $rectangle = new Rectangle(800, 600); - $result = $rectangle->containMax(1600, 1200); - $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); - } -} diff --git a/tests/Unit/Geometry/Traits/HasBackgroundColorTest.php b/tests/Unit/Geometry/Traits/HasBackgroundColorTest.php deleted file mode 100644 index dea09bd1..00000000 --- a/tests/Unit/Geometry/Traits/HasBackgroundColorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -getTestObject(); - $this->assertNull($object->backgroundColor()); - $this->assertFalse($object->hasBackgroundColor()); - $object->setBackgroundColor('fff'); - $this->assertEquals('fff', $object->backgroundColor()); - $this->assertTrue($object->hasBackgroundColor()); - } -} diff --git a/tests/Unit/Geometry/Traits/HasBorderTest.php b/tests/Unit/Geometry/Traits/HasBorderTest.php deleted file mode 100644 index 2d311612..00000000 --- a/tests/Unit/Geometry/Traits/HasBorderTest.php +++ /dev/null @@ -1,57 +0,0 @@ -getTestObject(); - $this->assertNull($object->borderColor()); - $this->assertEquals(0, $object->borderSize()); - $this->assertFalse($object->hasBorder()); - $object->setBorder('fff', 10); - $this->assertEquals('fff', $object->borderColor()); - $this->assertEquals(10, $object->borderSize()); - $this->assertTrue($object->hasBorder()); - } - - public function testSetBorderSize(): void - { - $object = $this->getTestObject(); - $this->assertEquals(0, $object->borderSize()); - $object->setBorderSize(10); - $this->assertEquals(10, $object->borderSize()); - } - - public function testSetBorderColor(): void - { - $object = $this->getTestObject(); - $this->assertNull($object->borderColor()); - $object->setBorderColor('fff'); - $this->assertEquals('fff', $object->borderColor()); - $this->assertFalse($object->hasBorder()); - } - - public function testHasBorder(): void - { - $object = $this->getTestObject(); - $this->assertFalse($object->hasBorder()); - $object->setBorderColor('fff'); - $this->assertFalse($object->hasBorder()); - $object->setBorderSize(1); - $this->assertTrue($object->hasBorder()); - } -} diff --git a/tests/Unit/HeicTest.php b/tests/Unit/HeicTest.php new file mode 100644 index 00000000..fa62bad0 --- /dev/null +++ b/tests/Unit/HeicTest.php @@ -0,0 +1,20 @@ +read($manager->create(100, 100)->encode(new MediaTypeEncoder('image/heic'))->toFilePointer()); + $this->assertInstanceOf(Image::class, $img); + } +} diff --git a/tests/Unit/ImageManagerTestGd.php b/tests/Unit/ImageManagerTestGd.php deleted file mode 100644 index 78352096..00000000 --- a/tests/Unit/ImageManagerTestGd.php +++ /dev/null @@ -1,157 +0,0 @@ -assertInstanceOf(ImageManager::class, $manager); - - $manager = new ImageManager(Driver::class); - $this->assertInstanceOf(ImageManager::class, $manager); - } - - public function testWithDriver(): void - { - $manager = ImageManager::withDriver(new Driver()); - $this->assertInstanceOf(ImageManager::class, $manager); - - $manager = ImageManager::withDriver(Driver::class); - $this->assertInstanceOf(ImageManager::class, $manager); - } - - public function testDriver(): void - { - $driver = new Driver(); - $manager = ImageManager::withDriver($driver); - $this->assertEquals($driver, $manager->driver()); - } - - public function testDriverStatic(): void - { - $manager = ImageManager::gd(); - $this->assertInstanceOf(ImageManager::class, $manager); - } - - public function testCreate(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->create(5, 4); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testAnimate(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->animate(function ($animation) { - $animation->add($this->getTestResourcePath('red.gif'), .25); - }); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testRead(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif')); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderClassname(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), FilePathImageDecoder::class); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderInstance(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), new FilePathImageDecoder()); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderClassnameArray(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), [FilePathImageDecoder::class]); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderInstanceArray(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), [new FilePathImageDecoder()]); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderInstanceArrayMultiple(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), [ - new BinaryImageDecoder(), - new FilePathImageDecoder(), - ]); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithRotationAdjustment(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('orientation.jpg')); - $this->assertColor(1, 0, 254, 255, $image->pickColor(3, 3)); - } - - public function testReadWithoutRotationAdjustment(): void - { - $manager = new ImageManager(Driver::class, autoOrientation: false); - $image = $manager->read($this->getTestResourcePath('orientation.jpg')); - $this->assertColor(250, 2, 3, 255, $image->pickColor(3, 3)); - } - - public function testReadAnimation(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('animation.gif')); - $this->assertTrue($image->isAnimated()); - } - - public function testReadAnimationDiscarded(): void - { - $manager = new ImageManager(Driver::class, decodeAnimation: false); - $image = $manager->read($this->getTestResourcePath('animation.gif')); - $this->assertFalse($image->isAnimated()); - } - - public function testApplyBlendingColorDefault(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('blocks.png')); - $result = $image->blendTransparency(); - $this->assertColor(255, 255, 255, 255, $image->pickColor(530, 0)); - $this->assertColor(255, 255, 255, 255, $result->pickColor(530, 0)); - } - - public function testApplyBlendingColorConfigured(): void - { - $manager = new ImageManager(Driver::class, blendingColor: 'ff5500'); - $image = $manager->read($this->getTestResourcePath('blocks.png')); - $result = $image->blendTransparency(); - $this->assertColor(255, 85, 0, 255, $image->pickColor(530, 0)); - $this->assertColor(255, 85, 0, 255, $result->pickColor(530, 0)); - } -} diff --git a/tests/Unit/ImageManagerTestImagick.php b/tests/Unit/ImageManagerTestImagick.php deleted file mode 100644 index 422229b1..00000000 --- a/tests/Unit/ImageManagerTestImagick.php +++ /dev/null @@ -1,157 +0,0 @@ -assertInstanceOf(ImageManager::class, $manager); - - $manager = new ImageManager(Driver::class); - $this->assertInstanceOf(ImageManager::class, $manager); - } - - public function testWithDriver(): void - { - $manager = ImageManager::withDriver(new Driver()); - $this->assertInstanceOf(ImageManager::class, $manager); - - $manager = ImageManager::withDriver(Driver::class); - $this->assertInstanceOf(ImageManager::class, $manager); - } - - public function testDriver(): void - { - $driver = new Driver(); - $manager = ImageManager::withDriver($driver); - $this->assertEquals($driver, $manager->driver()); - } - - public function testDriverStatic(): void - { - $manager = ImageManager::imagick(); - $this->assertInstanceOf(ImageManager::class, $manager); - } - - public function testCreate(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->create(5, 4); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testAnimate(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->animate(function ($animation) { - $animation->add($this->getTestResourcePath('red.gif'), .25); - }); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testRead(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif')); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderClassname(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), FilePathImageDecoder::class); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderInstance(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), new FilePathImageDecoder()); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderClassnameArray(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), [FilePathImageDecoder::class]); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderInstanceArray(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), [new FilePathImageDecoder()]); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithDecoderInstanceArrayMultiple(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('red.gif'), [ - new BinaryImageDecoder(), - new FilePathImageDecoder(), - ]); - $this->assertInstanceOf(ImageInterface::class, $image); - } - - public function testReadWithRotationAdjustment(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('orientation.jpg')); - $this->assertColor(1, 0, 254, 255, $image->pickColor(3, 3)); - } - - public function testReadWithoutRotationAdjustment(): void - { - $manager = new ImageManager(Driver::class, autoOrientation: false); - $image = $manager->read($this->getTestResourcePath('orientation.jpg')); - $this->assertColor(250, 2, 3, 255, $image->pickColor(3, 3)); - } - - public function testReadAnimation(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('animation.gif')); - $this->assertTrue($image->isAnimated()); - } - - public function testReadAnimationDiscarded(): void - { - $manager = new ImageManager(Driver::class, decodeAnimation: false); - $image = $manager->read($this->getTestResourcePath('animation.gif')); - $this->assertFalse($image->isAnimated()); - } - - public function testApplyBlendingColor(): void - { - $manager = new ImageManager(Driver::class); - $image = $manager->read($this->getTestResourcePath('blocks.png')); - $result = $image->blendTransparency(); - $this->assertColor(255, 255, 255, 255, $image->pickColor(530, 0)); - $this->assertColor(255, 255, 255, 255, $result->pickColor(530, 0)); - } - - public function testApplyBlendingColorConfigured(): void - { - $manager = new ImageManager(Driver::class, blendingColor: 'ff5500'); - $image = $manager->read($this->getTestResourcePath('blocks.png')); - $result = $image->blendTransparency(); - $this->assertColor(255, 85, 0, 255, $image->pickColor(530, 0)); - $this->assertColor(255, 85, 0, 255, $result->pickColor(530, 0)); - } -} diff --git a/tests/Unit/InputHandlerTest.php b/tests/Unit/InputHandlerTest.php deleted file mode 100644 index f231d8f1..00000000 --- a/tests/Unit/InputHandlerTest.php +++ /dev/null @@ -1,74 +0,0 @@ -assertInstanceOf($outputClassname, $handler->handle($input)); - } else { - $this->expectException($outputClassname); - $handler->handle($input); - } - } - - public static function testHandleProvider(): array - { - $base = [ - [null, DecoderException::class], - ['', DecoderException::class], - ['fff', ColorInterface::class], - ['rgba(0, 0, 0, 0)', ColorInterface::class], - ['cmyk(0, 0, 0, 0)', ColorInterface::class], - ['hsv(0, 0, 0)', ColorInterface::class], - ['hsl(0, 0, 0)', ColorInterface::class], - ['transparent', ColorInterface::class], - ['steelblue', ColorInterface::class], - [self::getTestResourcePath(), ImageInterface::class], - [file_get_contents(self::getTestResourcePath()), ImageInterface::class], - ]; - - $data = []; - $drivers = [GdDriver::class, ImagickDriver::class]; - foreach ($drivers as $driver) { - foreach ($base as $line) { - array_unshift($line, $driver); // prepend driver - $data[] = $line; - } - } - - return $data; - } - - public function testResolveWithoutDriver(): void - { - $handler = new InputHandler([new HexColorDecoder()]); - $result = $handler->handle('fff'); - $this->assertInstanceOf(ColorInterface::class, $result); - - $handler = new InputHandler([HexColorDecoder::class]); - $result = $handler->handle('fff'); - $this->assertInstanceOf(ColorInterface::class, $result); - } -} diff --git a/tests/Unit/MediaTypeTest.php b/tests/Unit/MediaTypeTest.php deleted file mode 100644 index aeca4bc2..00000000 --- a/tests/Unit/MediaTypeTest.php +++ /dev/null @@ -1,152 +0,0 @@ -assertEquals(Format::JPEG, $mime->format()); - - $mime = MediaType::IMAGE_PJPEG; - $this->assertEquals(Format::JPEG, $mime->format()); - - $mime = MediaType::IMAGE_JPG; - $this->assertEquals(Format::JPEG, $mime->format()); - - $mime = MediaType::IMAGE_X_JPEG; - $this->assertEquals(Format::JPEG, $mime->format()); - } - - public function testFormatWebp(): void - { - $mime = MediaType::IMAGE_WEBP; - $this->assertEquals(Format::WEBP, $mime->format()); - - $mime = MediaType::IMAGE_X_WEBP; - $this->assertEquals(Format::WEBP, $mime->format()); - } - - public function testFormatGif(): void - { - $mime = MediaType::IMAGE_GIF; - $this->assertEquals(Format::GIF, $mime->format()); - } - - public function testFormatPng(): void - { - $mime = MediaType::IMAGE_PNG; - $this->assertEquals(Format::PNG, $mime->format()); - - $mime = MediaType::IMAGE_X_PNG; - $this->assertEquals(Format::PNG, $mime->format()); - } - - public function testFormatAvif(): void - { - $mime = MediaType::IMAGE_AVIF; - $this->assertEquals(Format::AVIF, $mime->format()); - - $mime = MediaType::IMAGE_X_AVIF; - $this->assertEquals(Format::AVIF, $mime->format()); - } - - public function testFormatBmp(): void - { - $mime = MediaType::IMAGE_BMP; - $this->assertEquals(Format::BMP, $mime->format()); - - $mime = MediaType::IMAGE_X_BMP; - $this->assertEquals(Format::BMP, $mime->format()); - - $mime = MediaType::IMAGE_X_BITMAP; - $this->assertEquals(Format::BMP, $mime->format()); - - $mime = MediaType::IMAGE_X_WIN_BITMAP; - $this->assertEquals(Format::BMP, $mime->format()); - - $mime = MediaType::IMAGE_X_WINDOWS_BMP; - $this->assertEquals(Format::BMP, $mime->format()); - } - - public function testFormatTiff(): void - { - $mime = MediaType::IMAGE_TIFF; - $this->assertEquals(Format::TIFF, $mime->format()); - } - - public function testFormatJpeg2000(): void - { - $mime = MediaType::IMAGE_JPM; - $this->assertEquals(Format::JP2, $mime->format()); - - $mime = MediaType::IMAGE_JPX; - $this->assertEquals(Format::JP2, $mime->format()); - - $mime = MediaType::IMAGE_JP2; - $this->assertEquals(Format::JP2, $mime->format()); - } - - public function testFormatHeic(): void - { - $mime = MediaType::IMAGE_HEIC; - $this->assertEquals(Format::HEIC, $mime->format()); - - $mime = MediaType::IMAGE_X_HEIC; - $this->assertEquals(Format::HEIC, $mime->format()); - - $mime = MediaType::IMAGE_HEIF; - $this->assertEquals(Format::HEIC, $mime->format()); - } - - #[DataProvider('fileExtensionsDataProvider')] - public function testFileExtensions( - MediaType $mediaType, - int $fileExtensionCount, - FileExtension $fileExtension - ): void { - $this->assertCount($fileExtensionCount, $mediaType->fileExtensions()); - $this->assertEquals($fileExtension, $mediaType->fileExtension()); - } - - public static function fileExtensionsDataProvider(): array - { - return [ - [MediaType::IMAGE_JPEG, 2, FileExtension::JPG], - [MediaType::IMAGE_JPG, 2, FileExtension::JPG], - [MediaType::IMAGE_PJPEG, 2, FileExtension::JPG], - [MediaType::IMAGE_X_JPEG, 2, FileExtension::JPG], - [MediaType::IMAGE_WEBP, 1, FileExtension::WEBP], - [MediaType::IMAGE_X_WEBP, 1, FileExtension::WEBP], - [MediaType::IMAGE_GIF, 1, FileExtension::GIF], - [MediaType::IMAGE_PNG, 1, FileExtension::PNG], - [MediaType::IMAGE_X_PNG, 1, FileExtension::PNG], - [MediaType::IMAGE_AVIF, 1, FileExtension::AVIF], - [MediaType::IMAGE_X_AVIF, 1, FileExtension::AVIF], - [MediaType::IMAGE_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_MS_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_BITMAP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_MS_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_WINDOWS_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_WIN_BITMAP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_XBITMAP, 1, FileExtension::BMP], - [MediaType::IMAGE_TIFF, 2, FileExtension::TIF], - [MediaType::IMAGE_JP2, 8, FileExtension::JP2], - [MediaType::IMAGE_JPX, 8, FileExtension::JP2], - [MediaType::IMAGE_JPM, 8, FileExtension::JP2], - [MediaType::IMAGE_HEIC, 2, FileExtension::HEIC], - [MediaType::IMAGE_X_HEIC, 2, FileExtension::HEIC], - [MediaType::IMAGE_HEIF, 2, FileExtension::HEIC], - ]; - } -} diff --git a/tests/Unit/ModifierStackTest.php b/tests/Unit/ModifierStackTest.php deleted file mode 100644 index 8d63f423..00000000 --- a/tests/Unit/ModifierStackTest.php +++ /dev/null @@ -1,45 +0,0 @@ -assertInstanceOf(ModifierStack::class, $stack); - } - - public function testPush(): void - { - $stack = new ModifierStack([]); - $result = $stack->push(new GreyscaleModifier()); - $this->assertInstanceOf(ModifierStack::class, $result); - } - - public function testApply(): void - { - $image = Mockery::mock(ImageInterface::class); - - $modifier1 = Mockery::mock(ModifierInterface::class)->makePartial(); - $modifier1->shouldReceive('apply')->once()->with($image); - - $modifier2 = Mockery::mock(ModifierInterface::class)->makePartial(); - $modifier2->shouldReceive('apply')->once()->with($image); - - $stack = new ModifierStack([$modifier1, $modifier2]); - $result = $stack->apply($image); - $this->assertInstanceOf(ImageInterface::class, $result); - } -} diff --git a/tests/Unit/Modifiers/ColorspaceModifierTest.php b/tests/Unit/Modifiers/ColorspaceModifierTest.php deleted file mode 100644 index d5cfc12e..00000000 --- a/tests/Unit/Modifiers/ColorspaceModifierTest.php +++ /dev/null @@ -1,30 +0,0 @@ -assertInstanceOf(ColorspaceInterface::class, $modifier->targetColorspace()); - - $modifier = new ColorspaceModifier('rgb'); - $this->assertInstanceOf(ColorspaceInterface::class, $modifier->targetColorspace()); - - $modifier = new ColorspaceModifier('cmyk'); - $this->assertInstanceOf(ColorspaceInterface::class, $modifier->targetColorspace()); - - $modifier = new ColorspaceModifier('test'); - $this->expectException(NotSupportedException::class); - $modifier->targetColorspace(); - } -} diff --git a/tests/Unit/Modifiers/PadModifierTest.php b/tests/Unit/Modifiers/PadModifierTest.php deleted file mode 100644 index 777c7752..00000000 --- a/tests/Unit/Modifiers/PadModifierTest.php +++ /dev/null @@ -1,24 +0,0 @@ -shouldReceive('size')->andReturn($size); - $this->assertInstanceOf(SizeInterface::class, $modifier->getCropSize($image)); - } -} diff --git a/tests/Unit/Modifiers/TextModifierTest.php b/tests/Unit/Modifiers/TextModifierTest.php deleted file mode 100644 index 6db0c88f..00000000 --- a/tests/Unit/Modifiers/TextModifierTest.php +++ /dev/null @@ -1,38 +0,0 @@ -strokeOffsets($font); - } - }; - - $this->assertEquals([], $modifier->testStrokeOffsets(new Font())); - - $this->assertEquals([ - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, -1), - new Point(0, 0), - new Point(0, 1), - new Point(1, -1), - new Point(1, 0), - new Point(1, 1), - ], $modifier->testStrokeOffsets((new Font())->setStrokeWidth(1))); - } -} diff --git a/tests/Unit/OriginTest.php b/tests/Unit/OriginTest.php deleted file mode 100644 index 2932ed48..00000000 --- a/tests/Unit/OriginTest.php +++ /dev/null @@ -1,39 +0,0 @@ -getTestResourcePath('example.jpg')); - $this->assertEquals($this->getTestResourcePath('example.jpg'), $origin->filePath()); - } - - public function testFileExtension(): void - { - $origin = new Origin('image/jpeg', $this->getTestResourcePath('example.jpg')); - $this->assertEquals('jpg', $origin->fileExtension()); - - $origin = new Origin('image/jpeg'); - $this->assertEquals('', $origin->fileExtension()); - } - - public function testSetGetMediaType(): void - { - $origin = new Origin(); - $this->assertEquals('application/octet-stream', $origin->mediaType()); - - $origin = new Origin('image/gif'); - $this->assertEquals('image/gif', $origin->mediaType()); - $this->assertEquals('image/gif', $origin->mimetype()); - $result = $origin->setMediaType('image/jpeg'); - $this->assertEquals('image/jpeg', $origin->mediaType()); - $this->assertEquals('image/jpeg', $result->mediaType()); - } -} diff --git a/tests/Unit/ResolutionTest.php b/tests/Unit/ResolutionTest.php deleted file mode 100644 index e0e4c844..00000000 --- a/tests/Unit/ResolutionTest.php +++ /dev/null @@ -1,58 +0,0 @@ -assertInstanceOf(Resolution::class, $resolution); - } - - public function testXY(): void - { - $resolution = new Resolution(1.2, 3.4); - $this->assertEquals(1.2, $resolution->x()); - $this->assertEquals(3.4, $resolution->y()); - } - - public function testPerInch(): void - { - $resolution = new Resolution(300, 150); // per inch - $this->assertEquals(300, $resolution->perInch()->x()); - $this->assertEquals(150, $resolution->perInch()->y()); - - $resolution = new Resolution(300, 150, Resolution::PER_CM); - $this->assertEquals(118.11024, round($resolution->perInch()->x(), 5)); - $this->assertEquals(59.05512, round($resolution->perInch()->y(), 5)); - } - - public function testPerCm(): void - { - $resolution = new Resolution(118.11024, 59.05512); // per inch - $this->assertEquals(300, round($resolution->perCm()->x())); - $this->assertEquals(150, round($resolution->perCm()->y())); - - $resolution = new Resolution(300, 150, Resolution::PER_CM); - $this->assertEquals(300, $resolution->perCm()->x()); - $this->assertEquals(150, $resolution->perCm()->y()); - } - - public function testToString(): void - { - $resolution = new Resolution(300, 150, Resolution::PER_CM); - $this->assertEquals('300.00 x 150.00 dpcm', $resolution->toString()); - - $resolution = new Resolution(300, 150, Resolution::PER_INCH); - $this->assertEquals('300.00 x 150.00 dpi', $resolution->toString()); - $this->assertEquals('300.00 x 150.00 dpi', (string) $resolution); - } -} diff --git a/tests/Unit/Typography/FontFactoryTest.php b/tests/Unit/Typography/FontFactoryTest.php deleted file mode 100644 index 7afd9e80..00000000 --- a/tests/Unit/Typography/FontFactoryTest.php +++ /dev/null @@ -1,50 +0,0 @@ -getTestResourcePath('test.ttf'); - $factory = new FontFactory(new Font($font_file)); - $result = $factory(); - $this->assertInstanceOf(FontInterface::class, $result); - $this->assertEquals($font_file, $result->filename()); - } - - public function testBuildWithCallback(): void - { - $factory = new FontFactory(function (FontFactory $font) { - $font->filename($this->getTestResourcePath('test.ttf')); - $font->color('#b01735'); - $font->size(70); - $font->align('center'); - $font->valign('middle'); - $font->lineHeight(1.6); - $font->angle(10); - $font->wrap(100); - $font->stroke('ff5500', 4); - }); - - $result = $factory(); - $this->assertInstanceOf(FontInterface::class, $result); - $this->assertEquals($this->getTestResourcePath('test.ttf'), $result->filename()); - $this->assertEquals('#b01735', $result->color()); - $this->assertEquals(70, $result->size()); - $this->assertEquals('center', $result->alignment()); - $this->assertEquals('middle', $result->valignment()); - $this->assertEquals(1.6, $result->lineHeight()); - $this->assertEquals(10, $result->angle()); - $this->assertEquals(100, $result->wrapWidth()); - $this->assertEquals(4, $result->strokeWidth()); - $this->assertEquals('ff5500', $result->strokeColor()); - } -} diff --git a/tests/Unit/Typography/FontTest.php b/tests/Unit/Typography/FontTest.php deleted file mode 100644 index 06e68b29..00000000 --- a/tests/Unit/Typography/FontTest.php +++ /dev/null @@ -1,110 +0,0 @@ -assertInstanceOf(Font::class, $font); - $this->assertEquals('foo.ttf', $font->filename()); - } - - public function testSetGetSize(): void - { - $font = new Font(); - $this->assertEquals(12, $font->size()); - $result = $font->setSize(123); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals(123, $font->size()); - } - - public function testSetGetAngle(): void - { - $font = new Font(); - $this->assertEquals(0, $font->angle()); - $result = $font->setAngle(123); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals(123, $font->angle()); - } - - public function testSetGetFilename(): void - { - $font = new Font(); - $this->assertEquals(null, $font->filename()); - $this->assertFalse($font->hasFilename()); - $filename = $this->getTestResourcePath(); - $result = $font->setFilename($filename); - $this->assertTrue($font->hasFilename()); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals($filename, $font->filename()); - } - - public function testSetGetColor(): void - { - $font = new Font(); - $this->assertEquals('000000', $font->color()); - $result = $font->setColor('fff'); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals('fff', $font->color()); - } - - public function testSetGetAlignment(): void - { - $font = new Font(); - $this->assertEquals('left', $font->alignment()); - $result = $font->setAlignment('center'); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals('center', $font->alignment()); - } - - public function testSetGetValignment(): void - { - $font = new Font(); - $this->assertEquals('bottom', $font->valignment()); - $result = $font->setValignment('center'); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals('center', $font->valignment()); - } - - public function testSetGetLineHeight(): void - { - $font = new Font(); - $this->assertEquals(1.25, $font->lineHeight()); - $result = $font->setLineHeight(3.2); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals(3.2, $font->lineHeight()); - } - - public function testSetGetStrokeColor(): void - { - $font = new Font(); - $this->assertEquals('ffffff', $font->strokeColor()); - $result = $font->setStrokeColor('000000'); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals('000000', $font->strokeColor()); - } - - public function testSetGetStrokeWidth(): void - { - $font = new Font(); - $this->assertEquals(0, $font->strokeWidth()); - $result = $font->setStrokeWidth(4); - $this->assertInstanceOf(Font::class, $result); - $this->assertEquals(4, $font->strokeWidth()); - } - - public function testSetStrokeWidthOutOfRange(): void - { - $font = new Font(); - $this->expectException(FontException::class); - $font->setStrokeWidth(11); - } -} diff --git a/tests/Unit/Typography/LineTest.php b/tests/Unit/Typography/LineTest.php deleted file mode 100644 index 4f313441..00000000 --- a/tests/Unit/Typography/LineTest.php +++ /dev/null @@ -1,76 +0,0 @@ -assertInstanceOf(Line::class, $line); - } - - public function testToString(): void - { - $line = new Line('foo bar'); - $this->assertEquals('foo bar', (string) $line); - } - - public function testSetGetPosition(): void - { - $line = new Line('foo'); - $this->assertEquals(0, $line->position()->x()); - $this->assertEquals(0, $line->position()->y()); - - $line->setPosition(new Point(10, 11)); - $this->assertEquals(10, $line->position()->x()); - $this->assertEquals(11, $line->position()->y()); - } - - public function testCount(): void - { - $line = new Line(); - $this->assertEquals(0, $line->count()); - - $line = new Line("foo"); - $this->assertEquals(1, $line->count()); - - $line = new Line("foo bar"); - $this->assertEquals(2, $line->count()); - } - - public function testLength(): void - { - $line = new Line(); - $this->assertEquals(0, $line->length()); - - $line = new Line("foo"); - $this->assertEquals(3, $line->length()); - - $line = new Line("foo bar."); - $this->assertEquals(8, $line->length()); - - $line = new Line("🫷🙂🫸"); - $this->assertEquals(3, $line->length()); - } - - public function testAdd(): void - { - $line = new Line(); - $this->assertEquals(0, $line->count()); - - $result = $line->add('foo'); - $this->assertEquals(1, $line->count()); - $this->assertEquals(1, $result->count()); - - $result = $line->add('bar'); - $this->assertEquals(2, $line->count()); - $this->assertEquals(2, $result->count()); - } -} diff --git a/tests/Unit/Typography/TextBlockTest.php b/tests/Unit/Typography/TextBlockTest.php deleted file mode 100644 index 2ed9329a..00000000 --- a/tests/Unit/Typography/TextBlockTest.php +++ /dev/null @@ -1,46 +0,0 @@ -block = new TextBlock(<<assertEquals(3, $this->block->count()); - } - - public function testLines(): void - { - $this->assertCount(3, $this->block->lines()); - } - - public function testGetLine(): void - { - $this->assertEquals('foo', $this->block->line(0)); - $this->assertEquals('FooBar', $this->block->line(1)); - $this->assertEquals('bar', $this->block->line(2)); - $this->assertNull($this->block->line(20)); - } - - public function testLongestLine(): void - { - $result = $this->block->longestLine(); - $this->assertEquals('FooBar', (string) $result); - } -}