48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace Tests\Unit;
|
||
|
||
use Modules\EcommerceFinance\Services\DingInvoiceTextParser;
|
||
use Tests\TestCase;
|
||
|
||
class DingInvoiceTextParserTest extends TestCase
|
||
{
|
||
public function test_parses_standard_electronic_invoice_text(): void
|
||
{
|
||
$text = <<<'TEXT'
|
||
电子发票(普通发票)
|
||
发票号码:26320000000000000001
|
||
开票日期:2026年10月10日
|
||
购买方信息
|
||
名称:常州测试家居有限公司
|
||
统一社会信用代码/纳税人识别号:91320411MA00000001
|
||
销售方信息
|
||
名称:常州测试供应商有限公司
|
||
统一社会信用代码/纳税人识别号:91320411MA00000002
|
||
*办公用品*打印纸
|
||
金额:884.96
|
||
税率/征收率:13%
|
||
税额:115.04
|
||
价税合计(小写):¥1000.00
|
||
TEXT;
|
||
|
||
$invoice = app(DingInvoiceTextParser::class)->parse($text);
|
||
|
||
$this->assertNotNull($invoice);
|
||
$this->assertSame('电子发票(普通发票)', $invoice['invoice_type']);
|
||
$this->assertSame('26320000000000000001', $invoice['invoice_number']);
|
||
$this->assertSame('2026-10-10', $invoice['invoice_date']);
|
||
$this->assertSame('常州测试家居有限公司', $invoice['buyer_name']);
|
||
$this->assertSame('常州测试供应商有限公司', $invoice['seller_name']);
|
||
$this->assertEqualsWithDelta(1000.0, $invoice['invoice_total'], 0.001);
|
||
$this->assertSame('*办公用品*打印纸', $invoice['item_name']);
|
||
}
|
||
|
||
public function test_ignores_non_invoice_attachment_text(): void
|
||
{
|
||
$this->assertNull(
|
||
app(DingInvoiceTextParser::class)->parse('银行电子回单 金额 1000.00 无发票号码'),
|
||
);
|
||
}
|
||
}
|