nhance-enrollment/tests/_support/TestUploadedFile.php

41 lines
982 B
PHP

<?php
namespace Tests\Support;
use CodeIgniter\HTTP\Files\UploadedFile;
/**
* UploadedFile stub for CLI tests — bypasses is_uploaded_file() / move_uploaded_file().
*/
class TestUploadedFile extends UploadedFile
{
public function isValid(): bool
{
return $this->getError() === UPLOAD_ERR_OK && is_file($this->getTempName());
}
public function move(string $targetPath, ?string $name = null, bool $overwrite = false)
{
$targetPath = rtrim($targetPath, '/') . '/';
if (!is_dir($targetPath)) {
mkdir($targetPath, 0777, true);
}
$name ??= $this->getName();
$destination = $targetPath . $name;
if (!$overwrite && is_file($destination)) {
$destination = $targetPath . uniqid('test_', true) . '_' . $name;
}
if (!copy($this->getTempName(), $destination)) {
return false;
}
@unlink($this->getTempName());
return true;
}
}