CaiWuXiTong/tests/Unit/Business/XlsxSheetReaderTest.php
renshen 0bf1ae67af 导入订单售后与商品推广月度明细 (#578)
新增 2026-06 月度订单售后及商品推广导入能力
2026-10-26 11:09:22 +08:00

40 lines
1.2 KiB
PHP

<?php
namespace Tests\Unit\Business;
use App\Business\XlsxSheetReader;
use PHPUnit\Framework\TestCase;
use ZipArchive;
class XlsxSheetReaderTest extends TestCase
{
public function test_it_reads_worksheets_with_prefixed_xml_elements(): void
{
$path = tempnam(sys_get_temp_dir(), 'xlsx-prefixed') . '.xlsx';
$zip = new ZipArchive();
$zip->open($path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addFromString('xl/worksheets/sheet1.xml', <<<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<x:worksheet xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:sheetData>
<x:row r="1">
<x:c r="A1" t="inlineStr"><x:is><x:t>店铺</x:t></x:is></x:c>
<x:c r="B1" t="inlineStr"><x:is><x:t>商品编码</x:t></x:is></x:c>
</x:row>
<x:row r="2">
<x:c r="A2" t="inlineStr"><x:is><x:t>天猫-测试店</x:t></x:is></x:c>
<x:c r="B2" t="inlineStr"><x:is><x:t>SKU-1</x:t></x:is></x:c>
</x:row>
</x:sheetData>
</x:worksheet>
XML);
$zip->close();
$rows = iterator_to_array((new XlsxSheetReader())->rows($path, ['店铺', '商品编码']));
$this->assertSame([['店铺' => '天猫-测试店', '商品编码' => 'SKU-1']], $rows);
@unlink($path);
}
}