1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-17 04:08:14 +01:00
intervention_image/tests/TestCase.php

48 lines
1.4 KiB
PHP
Raw Normal View History

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;
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;
use Mockery\Adapter\Phpunit\MockeryTestCase;
2021-10-21 14:32:05 +02: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());
}
protected function assertTransparency(ColorInterface $color)
{
$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
}