You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Models\ApplicationFile;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Tests\TestCase;
|
|
|
|
class ApplicationFileAssertStoredTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_assert_stored_file_exists_rejects_invalid_path(): void
|
|
{
|
|
Storage::fake('public');
|
|
|
|
$file = new ApplicationFile([
|
|
'disk' => 'public',
|
|
'path' => '0',
|
|
]);
|
|
|
|
try {
|
|
$file->assertStoredFileExists();
|
|
$this->fail('Expected NotFoundHttpException');
|
|
} catch (NotFoundHttpException $e) {
|
|
$this->assertSame('附件文件不存在或已丢失', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function test_assert_stored_file_exists_passes_when_file_present(): void
|
|
{
|
|
Storage::fake('public');
|
|
Storage::disk('public')->put('applications/1/plan.pdf', 'ok');
|
|
|
|
$file = new ApplicationFile([
|
|
'disk' => 'public',
|
|
'path' => 'applications/1/plan.pdf',
|
|
]);
|
|
|
|
$file->assertStoredFileExists();
|
|
$this->addToAssertionCount(1);
|
|
}
|
|
}
|