createMock(UpstreamReadOnlyQuery::class); $upstream->expects($this->once()) ->method('select') ->with( $this->stringContains('WHERE o_id IN'), ['order-1'], ) ->willReturn([ [ 'o_id' => 'order-1', 'raw_so_id' => 'trade-1', 'sku_id' => 'sku-1', 'i_id' => 'item-1', 'shop_i_id' => 'shop-item-1', 'name' => '商品', 'qty' => 1, 'amount' => 10, 'send_warehouse' => 'δ»“εΊ“', 'Id' => 1, ], ]); $factory = $this->createMock(UpstreamReadOnlyQueryFactory::class); $factory->method('forSource')->with('operations_replica')->willReturn($upstream); $synchronizer = new ShippingReplicaSynchronizer($factory); $method = new \ReflectionMethod($synchronizer, 'loadAllItems'); $method->setAccessible(true); [$byOrder, $byTrade] = $method->invoke($synchronizer, ['order-1'], ['trade-1'], false); $this->assertArrayHasKey('order-1', $byOrder); $this->assertSame([], $byTrade); } public function test_sync_removes_only_the_known_demo_source_ids(): void { $db = DB::connection('business_mirror'); $db->table('jst_oms_shipping')->insert([ ['source_id' => 9000001, 'sku_source_id' => 9000001], ['source_id' => 9000006, 'sku_source_id' => 9000006], ['source_id' => 9000007, 'sku_source_id' => 9000007], ['source_id' => 999999999, 'sku_source_id' => 999999999], ]); $upstream = $this->createMock(UpstreamReadOnlyQuery::class); $upstream->expects($this->once())->method('select')->willReturn([]); $factory = $this->createMock(UpstreamReadOnlyQueryFactory::class); $factory->expects($this->once()) ->method('forSource') ->with('operations_replica') ->willReturn($upstream); $result = (new ShippingReplicaSynchronizer($factory))->sync(); $this->assertSame(['processed' => 0, 'autoship' => 0], $result); $this->assertSame( [9000007, 999999999], $db->table('jst_oms_shipping')->orderBy('source_id')->pluck('source_id')->map(fn ($id) => (int) $id)->all(), ); } }