Files
coruna-lab/tests/Feature/DsResultStoreTest.php
T
2026-09-17 00:25:39 +08:00

49 lines
1.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Device;
use App\Services\DsResultStore;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class DsResultStoreTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function assembles_chunks_without_keeping_a_concat_string(): void
{
Storage::fake('local');
$device = Device::query()->create([
'device_id' => 'DSCHUNKDEVICE01',
'album_storage' => false,
]);
$store = app(DsResultStore::class);
$pending = $store->store($device, [
'filename' => 'memo.bin',
'data' => base64_encode('AAA'),
'command_id' => 'cmd1',
'total_chunks' => 2,
'chunk_index' => 0,
]);
$this->assertFalse($pending['stored']);
$this->assertSame('chunk_pending', $pending['reason']);
$done = $store->store($device, [
'filename' => 'memo.bin',
'data' => base64_encode('BBB'),
'command_id' => 'cmd1',
'total_chunks' => 2,
'chunk_index' => 1,
]);
$this->assertTrue($done['stored']);
$this->assertSame(6, $done['size']);
Storage::disk('local')->assertExists($done['path']);
$this->assertSame('AAABBB', Storage::disk('local')->get($done['path']));
}
}