<?phpnamespace Tests;use App\Model\Skin;use App\Model\SkinParts;use PHPUnit\Framework\TestCase;/** Every skin given with WinZik loads without a warning and has every picture its windows draw. */final class SkinTest extends TestCase{ /** @return array<string, array{0: string}> */ public static function skins(): array { $out = []; foreach (glob(__DIR__ . '/../assets/skins/*', GLOB_ONLYDIR) ?: [] as $dir) { $out[basename($dir)] = [$dir]; } return $out; } #[\PHPUnit\Framework\Attributes\DataProvider('skins')] public function testTheSkinLoadsAndHasEveryPicture(string $dir): void { $errors = []; set_error_handler(function (int $no, string $message) use (&$errors): bool { $errors[] = $message; return true; }); try { self::assertTrue(Skin::isSkin($dir), 'an INFO.txt and a main picture'); $skin = new Skin($dir); $palette = $skin->palette(); } finally { restore_error_handler(); } self::assertSame([], $errors, 'no warning'); self::assertNotSame('', trim($skin->name)); self::assertCount(23, $skin->lineColors); foreach ([...array_values($skin->colors), ...$skin->lineColors, ...array_values($palette)] as $color) { self::assertMatchesRegularExpression('/^#[0-9a-f]{6}$/', $color); } $needed = ['ico']; foreach (SkinParts::WINDOWS as $window => [, $background]) { $needed[] = $background; $needed = [...$needed, ...array_keys(SkinParts::PARTS[$window])]; } foreach ($needed as $picture) { $file = $skin->image($picture); self::assertNotNull($file, "$picture is missing"); $size = @getimagesize($file); self::assertIsArray($size, "$picture can be read"); self::assertGreaterThan(0, $size[0] * $size[1], $picture); } if ($skin->vis !== null) { [$x, $y, $w, $h] = $skin->vis; self::assertGreaterThan(0, $w * $h, 'VIS.txt: a visualizer with a size'); } } public function testAFolderWithoutInfoOrBrokenInfoIsHandled(): void { $dir = sys_get_temp_dir() . '/wz-skin-' . bin2hex(random_bytes(3)); mkdir($dir); try { self::assertFalse(Skin::isSkin($dir)); file_put_contents($dir . '/info.txt', "pas un skin\n"); self::assertFalse(Skin::isSkin($dir), 'no main picture'); file_put_contents($dir . '/MAIN.BMP', 'x'); self::assertTrue(Skin::isSkin($dir)); $skin = new Skin($dir); self::assertSame(basename($dir), $skin->name, 'not [INF]: the folder name, the default colours'); self::assertSame('#ffff00', $skin->colors['title']); self::assertSame('#2a2a40', $skin->palette()['case'], 'no picture: the default palette'); $skin->readInfo("[INF]\r\nMon skin\r\n&H000000FF&\r\nrouge\r\n"); self::assertSame('Mon skin', $skin->name); self::assertSame('#ff0000', $skin->colors['title']); self::assertSame('#ffff00', $skin->colors['volume'], 'not a colour: kept'); self::assertSame('#8080ff', $skin->lineColor(99)); } finally { array_map('unlink', glob($dir . '/*') ?: []); rmdir($dir); } }}