/** * @dataProvider getTestFiles */ public function testFile($file, $expectedType) { $this->assertNotEmpty($file, 'File is empty'); $this->assertNotEmpty($expectedType, 'Expected type is empty'); $type = MIME_Type_PlainDetect::autoDetect($file); $this->assertEquals($expectedType, $type, 'MIME type not detected correctly'); }
/** * Try to find the magic file copied by phing's build.xml into * lib/data/. * * @return string path to the magic file */ public static function getMagicFile() { $rootdir = __DIR__ . '/../../../../../'; if (file_exists($rootdir . '/lib/PEAR.php')) { if (!\Phar::running()) { return $rootdir . '/lib/data/programming.magic'; } else { //magic file within a .phar does not work: // https://bugs.php.net/bug.php?id=67556 //put it outside $target = '/tmp/phorkie-programming.magic'; if (!file_exists($target)) { copy($rootdir . '/lib/data/programming.magic', $target); } return $target; } } return parent::getMagicFile(); }
<?php if ($argc !== 2) { echo "Please pass one and only one filename\n"; exit(1); } $file = $argv[1]; if (!is_readable($file)) { echo "File does not exist or is not readable\n"; exit(2); } if (is_dir(__DIR__ . '/src')) { set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/src'); } require_once 'MIME/Type/PlainDetect.php'; $type = MIME_Type_PlainDetect::autoDetect($file); if ($type == 'text/plain') { } echo $type . "\n";