| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Controllers;
- use App\Controllers\ImportController;
- use App\Tests\TestCase;
- use ReflectionMethod;
- /**
- * Phase 20 — pure-static guards on ImportController. Mirrors the
- * UserControllerTest pattern: exercise the bits that do not need PDO or
- * session wiring.
- */
- final class ImportControllerTest extends TestCase
- {
- public function testLooksLikeXlsxAcceptsRealZipHeader(): void
- {
- $tmp = tempnam(sys_get_temp_dir(), 'sptest');
- file_put_contents($tmp, "PK\x03\x04rest of the file");
- try {
- $this->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);
- }
- }
|