3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\Import\ImportSettings
;
9 use PHPUnit\Framework\Attributes\CoversClass
;
10 use PHPUnit\Framework\Attributes\DataProvider
;
11 use PHPUnit\Framework\Attributes\RequiresPhpExtension
;
14 use function file_get_contents
;
16 #[CoversClass(File::class)]
17 class FileTest
extends AbstractTestCase
20 * Setup function for test cases
22 protected function setUp(): void
26 ImportSettings
::$charsetConversion = false;
30 * Test for File::getCompression
32 * @param string $file file string
33 * @param string $mime expected mime
35 #[DataProvider('compressedFiles')]
36 public function testMIME(string $file, string $mime): void
38 $arr = new File($file);
39 self
::assertSame($mime, $arr->getCompression());
43 * Test for File::getContent
45 * @param string $file file string
47 #[DataProvider('compressedFiles')]
48 public function testBinaryContent(string $file): void
50 $data = '0x' . bin2hex((string) file_get_contents($file));
51 $file = new File($file);
52 self
::assertSame($data, $file->getContent());
58 * @param string $file file string
60 #[DataProvider('compressedFiles')]
61 #[RequiresPhpExtension('bz2')]
62 #[RequiresPhpExtension('zip')]
63 public function testReadCompressed(string $file): void
65 $file = new File($file);
66 $file->setDecompressContent(true);
68 self
::assertSame("TEST FILE\n", $file->read(100));
72 /** @return array<array{string, string}> */
73 public static function compressedFiles(): array
76 ['./tests/test_data/test.gz', 'application/gzip'],
77 ['./tests/test_data/test.bz2', 'application/bzip2'],
78 ['./tests/test_data/test.zip', 'application/zip'],