assertTrue(self::call('looksLikeXlsx', 'workbook.xlsx', $tmp)); $this->assertFalse(self::call('looksLikeXlsx', 'workbook.txt', $tmp), 'wrong extension'); } finally { unlink($tmp); } } public function testLooksLikeXlsxRejectsNonZip(): void { $tmp = tempnam(sys_get_temp_dir(), 'sptest'); file_put_contents($tmp, 'not a zip'); try { $this->assertFalse(self::call('looksLikeXlsx', 'workbook.xlsx', $tmp)); } finally { unlink($tmp); } } public function testLooksLikeXlsxRejectsTooShortFile(): void { $tmp = tempnam(sys_get_temp_dir(), 'sptest'); file_put_contents($tmp, 'PK'); try { $this->assertFalse(self::call('looksLikeXlsx', 'workbook.xlsx', $tmp)); } finally { unlink($tmp); } } public function testUploadErrorCodeMapping(): void { $this->assertSame('too_big', self::call('uploadErrorCode', UPLOAD_ERR_INI_SIZE)); $this->assertSame('too_big', self::call('uploadErrorCode', UPLOAD_ERR_FORM_SIZE)); $this->assertSame('partial', self::call('uploadErrorCode', UPLOAD_ERR_PARTIAL)); $this->assertSame('no_file', self::call('uploadErrorCode', UPLOAD_ERR_NO_FILE)); $this->assertSame('server', self::call('uploadErrorCode', UPLOAD_ERR_NO_TMP_DIR)); $this->assertSame('server', self::call('uploadErrorCode', UPLOAD_ERR_CANT_WRITE)); $this->assertSame('unknown', self::call('uploadErrorCode', 9999)); } /** * Reflectively call a private static helper on ImportController so we * don't need to expand its public surface for testability. */ private static function call(string $method, mixed ...$args): mixed { $r = new ReflectionMethod(ImportController::class, $method); $r->setAccessible(true); return $r->invoke(null, ...$args); } }