65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Console;
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Tests\TestCase;
|
|
|
|
class SyncBusinessFilesToQiniuTest extends TestCase
|
|
{
|
|
private string $markerPath;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->markerPath = storage_path('app/.business-storage-qiniu-synced');
|
|
File::delete($this->markerPath);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
File::delete($this->markerPath);
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_it_copies_retained_local_files_without_deleting_them(): void
|
|
{
|
|
config([
|
|
'business_storage.driver' => 'qiniu',
|
|
'business_storage.qiniu.access_key' => 'test-access-key',
|
|
'business_storage.qiniu.secret_key' => 'test-secret-key',
|
|
]);
|
|
Http::fake([
|
|
'https://caiwu.jiansun.vip/*' => Http::sequence()
|
|
->push('', 403)
|
|
->push('', 200),
|
|
]);
|
|
Storage::fake('business_uploads_local');
|
|
Storage::fake('business_uploads_qiniu');
|
|
Storage::disk('business_uploads_local')->put('2026/07/document.pdf', 'financial-document');
|
|
|
|
$this->artisan('storage:business-files:sync', ['--require-qiniu' => true])
|
|
->assertSuccessful();
|
|
|
|
Storage::disk('business_uploads_local')->assertExists('2026/07/document.pdf');
|
|
Storage::disk('business_uploads_qiniu')->assertExists('2026/07/document.pdf');
|
|
$this->assertSame(
|
|
'financial-document',
|
|
Storage::disk('business_uploads_qiniu')->get('2026/07/document.pdf')
|
|
);
|
|
$this->assertFileExists($this->markerPath);
|
|
}
|
|
|
|
public function test_it_fails_when_production_requires_qiniu_but_the_driver_is_local(): void
|
|
{
|
|
config(['business_storage.driver' => 'local']);
|
|
|
|
$this->artisan('storage:business-files:sync', ['--require-qiniu' => true])
|
|
->assertFailed();
|
|
}
|
|
}
|