1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 17:19:50 +02:00

PHPUnit 10 Migration (#1302)

* Bump PHPUnit dependencies

* Set return type of base TestCase methods

From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type:

- `setUpBeforeClass()`
- `setUp()`
- `assertPreConditions()`
- `assertPostConditions()`
- `tearDown()`
- `tearDownAfterClass()`
- `onNotSuccessfulTest()`

[1]: https://phpunit.de/announcements/phpunit-8.html

* Ignore PHPUnit cache folder

* Adopt PHP attributes in test classes

* Declare data providers as `static`

* Add return types to test methods

* Define test classes as `final`

* Migrate phpunit.xml to phpunit 10

* Correct phpunit attribute class name

* Rename base test class

* Restructure test folders

* Fix test image paths

* Only set rules for php files in .editorconfig

* Remove php unit flag in local test env

---------

Co-authored-by: Shift <shift@laravelshift.com>
This commit is contained in:
Oliver Vogel
2024-02-28 16:16:23 +01:00
committed by GitHub
parent fe1b0e2e64
commit dcc95b8299
183 changed files with 1347 additions and 1392 deletions

70
tests/BaseTestCase.php Normal file
View File

@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests;
use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Colors\Rgb\Color as RgbColor;
use Intervention\Image\Interfaces\ColorInterface;
use Mockery\Adapter\Phpunit\MockeryTestCase;
abstract class BaseTestCase extends MockeryTestCase
{
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));
}
protected function assertColor($r, $g, $b, $a, ColorInterface $color)
{
$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());
}
protected function assertMediaType(string|array $allowed, string $input): void
{
$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));
}
protected function assertMediaTypeBitmap(string $input): void
{
$this->assertMediaType([
'image/x-ms-bmp',
'image/bmp',
'bmp',
'ms-bmp',
'x-bitmap',
'x-bmp',
'x-ms-bmp',
'x-win-bitmap',
'x-windows-bmp',
'x-xbitmap',
'image/ms-bmp',
'image/x-bitmap',
'image/x-bmp',
'image/x-ms-bmp',
'image/x-win-bitmap',
'image/x-windows-bmp',
'image/x-xbitmap',
], $input);
}
}