2021-10-21 14:32:05 +02:00
|
|
|
<?php
|
|
|
|
|
2024-01-16 12:01:29 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-10-21 14:32:05 +02:00
|
|
|
namespace Intervention\Image\Tests;
|
|
|
|
|
2023-10-22 09:12:15 +02:00
|
|
|
use Intervention\Image\Colors\Rgb\Channels\Alpha;
|
|
|
|
use Intervention\Image\Colors\Rgb\Color as RgbColor;
|
2021-10-21 14:32:05 +02:00
|
|
|
use Intervention\Image\Interfaces\ColorInterface;
|
2021-12-07 11:00:06 +00:00
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase;
|
2021-10-21 14:32:05 +02:00
|
|
|
|
2021-12-07 11:00:06 +00:00
|
|
|
abstract class TestCase extends MockeryTestCase
|
2021-10-21 14:32:05 +02:00
|
|
|
{
|
2023-10-03 10:08:37 +02:00
|
|
|
public function getTestImagePath($filename = 'test.jpg'): string
|
|
|
|
{
|
|
|
|
return sprintf('%s/images/%s', __DIR__, $filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTestImageData($filename = 'test.jpg'): string
|
|
|
|
{
|
|
|
|
return file_get_contents($this->getTestImagePath($filename));
|
|
|
|
}
|
|
|
|
|
2021-10-21 14:32:05 +02:00
|
|
|
protected function assertColor($r, $g, $b, $a, ColorInterface $color)
|
|
|
|
{
|
2023-10-17 17:08:45 +02:00
|
|
|
$this->assertEquals([$r, $g, $b, $a], $color->toArray());
|
2021-12-07 11:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function assertTransparency(ColorInterface $color)
|
|
|
|
{
|
2023-10-22 09:12:15 +02:00
|
|
|
$this->assertInstanceOf(RgbColor::class, $color);
|
|
|
|
$channel = $color->channel(Alpha::class);
|
|
|
|
$this->assertEquals(0, $channel->value());
|
2021-10-21 14:32:05 +02:00
|
|
|
}
|
2023-11-12 11:32:08 +01:00
|
|
|
|
2023-12-17 16:42:16 +01:00
|
|
|
protected function assertMediaType(string|array $allowed, string $input): void
|
2023-11-12 11:32:08 +01:00
|
|
|
{
|
|
|
|
$pointer = fopen('php://temp', 'rw');
|
|
|
|
fputs($pointer, $input);
|
|
|
|
rewind($pointer);
|
|
|
|
$detected = mime_content_type($pointer);
|
|
|
|
fclose($pointer);
|
|
|
|
|
|
|
|
$allowed = is_string($allowed) ? [$allowed] : $allowed;
|
|
|
|
$this->assertTrue(in_array($detected, $allowed));
|
|
|
|
}
|
2021-10-21 14:32:05 +02:00
|
|
|
}
|