<?php

namespace Tests\Services\OrderPackageService\SyncOrderPackageTest;

use App\Services\OracleDOCOrderHeaderService;
use App\Services\OrderPackageService;
use App\Services\OrderService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class SyncOrderPackageTest extends TestCase
{
    /**
     * @var OrderPackageService $service
     * @var OracleDOCOrderHeaderService $orderHeaderService
     * @var OrderService $orderService
     */
    public $service;
    public $orderService;
    public $orderHeaderService;

    public function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderPackageService');
        $this->orderService = app('OrderService');
        $this->orderHeaderService = app('OracleDOCOrderHeaderService');
    }
    public function testSyncOrderPackage()
    {
        /*
       * createOrderPackage($orderHeaders,$orders,$packages)
       * */

        $carbon =Carbon::now()->subHours(10);
        $date = '2020-09-18 18:13:50';
        $orderHeaders = $this->orderHeaderService->getWMSOrderOnStartDate($carbon);
        if($orderHeaders->count()==0){
            var_dump('查询数据为空');
            return;
        }
        $orders = $this->orderService->getByWmsOrders($orderHeaders);
        $packages = $this->service->getByWmsOrders($orderHeaders);
        $this->service->syncOrderPackage($orderHeaders,$orders,$packages);
        $exits_packages  = $this->service->getByWmsOrders($orderHeaders);
        $exits_count = $exits_packages->count();
        $logistic_numbers = data_get($orderHeaders,'*.actAllocationDetails.*.picktotraceid');
        $logistic_numbers = array_unique(array_diff($logistic_numbers,['',' ','*']));
        $this->assertEquals(count($logistic_numbers),$exits_count);
        foreach ($logistic_numbers as $logistic_number) {
            $exits_package = $exits_packages->where('logistic_number',$logistic_number);
            $this->assertEmpty($exits_package);
            $this->assertEquals($exits_package->count(),1);
        }
    }
}
