CaiWuXiTong/tests/Unit/EcommerceFinance/StockQuoteShippingNamesTest.php

42 lines
1.9 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Modules\EcommerceFinance\Repositories\ShippingOrderRepository;
use Tests\TestCase;
class StockQuoteShippingNamesTest extends TestCase
{
public function test_candidates_preserve_shipping_names_without_scanning_history_or_requerying_each_keyword(): void
{
config(['jushuitan.connection' => 'sqlite']);
Cache::flush();
if (! Schema::hasTable('jst_oms_shipping')) {
Schema::create('jst_oms_shipping', function (Blueprint $table): void {
$table->increments('id');
$table->string('express_name1')->nullable();
$table->string('express_name2')->nullable();
});
}
DB::table('jst_oms_shipping')->insert(['id' => 1, 'express_name1' => '仅历史出现的快递', 'express_name2' => null]);
foreach (array_chunk(range(2, 10001), 500) as $ids) {
DB::table('jst_oms_shipping')->insert(array_map(fn ($id) => [
'id' => $id, 'express_name1' => '发货名称甲', 'express_name2' => $id === 10001 ? '发货名称乙' : '0',
], $ids));
}
$repository = new ShippingOrderRepository();
DB::enableQueryLog();
DB::flushQueryLog();
$this->assertSame(['发货名称乙', '发货名称甲'], $repository->recentCourierNames('发货名称'));
$this->assertSame([], $repository->recentCourierNames('仅历史'));
$this->assertCount(1, DB::getQueryLog());
DB::disableQueryLog();
$this->assertSame('仅历史出现的快递', DB::table('jst_oms_shipping')->where('id', 1)->value('express_name1'));
$this->assertSame(10001, DB::table('jst_oms_shipping')->count());
}
}