[array_replace([ 'Id' => '123', 'woNo' => 'GD-TEST', 'online_order_no' => '1234567890123456789', 'expected_status' => 'CONFIRMING', 'expected_updated_at' => '2026-11-16 10:10:45', 'completed_at' => '2026-11-16 11:56:18', ], $patch)]]; $disk = $this->createMock(Filesystem::class); $disk->method('exists')->with(PlantingWorkOrderCompletions::PATH)->willReturn(true); $disk->method('get')->willReturn(json_encode($document)); $factory = $this->createMock(Factory::class); $factory->method('disk')->with('local')->willReturn($disk); return new PlantingWorkOrderCompletions($factory); } private function row(array $patch = []): array { return array_replace([ 'Id' => 123, 'woNo' => 'GD-TEST', 'woTypeId' => Repository::WORK_TYPE_ID, 'status' => 'CONFIRMING', 'updated' => '2026-11-16 10:10:45.000000', 'completeTime' => null, 'businessFieldList' => json_encode([ ['fieldId' => 'orderField', 'value' => '1234567890123456789'], ['fieldId' => 'NUMBERField1413856620251117101250', 'value' => '0.01'], ]), ], $patch); } public function test_stale_resync_keeps_export_confirmed_completion_and_original_financial_fields(): void { $source = $this->row(); $expected = array_replace($source, ['status' => 'CONFIRMED', 'completeTime' => '2026-11-16 11:56:18']); $service = $this->service(); $this->assertSame([$expected], $service->apply([$source])); $this->assertSame([$expected], $service->apply([$source])); $this->assertSame([$expected], $service->apply([$expected])); } public function test_new_source_versions_and_other_work_orders_are_not_overridden(): void { foreach ([ ['Id' => 124], ['woNo' => 'GD-OTHER'], ['woTypeId' => 'OTHER'], ['status' => 'DISABLED'], ['status' => 'CONFIRMED', 'completeTime' => '2026-11-17 12:00:00'], ['updated' => '2026-11-16 12:00:00'], ['completeTime' => '2026-11-16 12:00:00'], ['businessFieldList' => json_encode([['fieldId' => 'orderField', 'value' => '1234567890123456790']])], ] as $patch) { $source = $this->row($patch); $this->assertSame([$source], $this->service()->apply([$source])); } } public function test_wrapped_business_fields_and_source_iso_times_are_supported(): void { $source = $this->row(['updated' => '2026-11-16T10:10:45.000', 'businessFieldList' => json_encode(['businessField' => [['fieldId' => 'orderField', 'valueLabel' => '', 'value' => '1234567890123456789']]])]); $this->assertSame('CONFIRMED', $this->service()->apply([$source])[0]['status']); } public function test_invalid_confirmation_fails_instead_of_silently_reverting_mirror_status(): void { $this->expectException(\RuntimeException::class); $this->service(['completed_at' => '2026-02-30 11:56:18'])->apply([$this->row()]); } }