create([ 'company_id' => $this->company->id, 'store_platform' => '拼多多', 'erp_store_name' => $storeName, 'shop_name' => $storeName, 'store_entity_name' => '历史旧主体', ]); $source = [[ 'id' => 701, 'store_id' => 'PDD-701', 'shop_name' => $storeName, 'erp_store_name' => $storeName, 'company_name' => '店铺基础信息旧主体', 'source_platform' => '拼多多', 'store_status' => '0', 'store_type' => 'POP', ]]; $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); $mirror->shouldReceive('receivingAccountStores')->once()->andReturn($source); $periods = Mockery::mock(StoreReportPeriodBuilder::class); $periods->shouldReceive('currentCompanies') ->once() ->with(Mockery::on( static fn (array $stores): bool => $stores === [[ 'erp_store_name' => $storeName, 'system_company_name' => '店铺基础信息旧主体', ]], )) ->andReturn([$storeName => '报表存续中主体']); $result = (new StoreReceivingAccountSynchronizer($mirror, $periods)) ->sync((int) $this->company->id); $this->assertSame(1, $result['updated']); $this->assertSame('报表存续中主体', $account->fresh()->store_entity_name); } public function test_sync_falls_back_to_store_information_company_when_no_current_period_exists(): void { $storeName = '天猫-无存续期主体店'; $source = [[ 'id' => 702, 'store_id' => 'TM-702', 'shop_name' => $storeName, 'erp_store_name' => $storeName, 'company_name' => '店铺基础信息主体', 'source_platform' => '天猫', 'store_status' => '0', 'store_type' => '旗舰店', ]]; $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); $mirror->shouldReceive('receivingAccountStores')->once()->andReturn($source); $periods = Mockery::mock(StoreReportPeriodBuilder::class); $periods->shouldReceive('currentCompanies')->once()->andReturn([]); (new StoreReceivingAccountSynchronizer($mirror, $periods)) ->sync((int) $this->company->id); $this->assertSame( '店铺基础信息主体', StoreReceivingAccount::withoutGlobalScopes() ->where('company_id', $this->company->id) ->where('store_name', $storeName) ->value('store_entity_name'), ); } }