<?php

namespace Tests\CacheService\LogisticTimingService\FindByParamsTest;

use App\City;
use App\Logistic;
use App\Province;
use App\Services\LogisticTimingService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class FindByParamsTest extends TestCase
{
    /**
     * @var LogisticTimingService $logisticTimingService
     */
    public $logisticTimingService;

    public function setUp(): void
    {
        parent::setUp();
        $this->logisticTimingService = app(LogisticTimingService::class);

        factory(Logistic::class)->create(['name'=>'新杰物流','code'=>'XJWL']);
        $province = null;
        if(!Province::query()->where('name','like','江苏')->exists())
            $province = factory(Province::class)->create(['name'=>'江苏']);
        else
            $province = Province::query()->where('name','like','江苏')->first();

        if(!city::query()->where('name','like','南京'))
            factory(City::class)->create(['name'=>'南京', 'province_id'=>$province->id]);
    }

    /**
     * @test
     */
    public function findByParams()
    {
        $cityName = '江苏省';
        $provinceName = '南京市';
        $logistic = Logistic::query()->where('name','like','新杰物流'.'%')->first();
        $result = $this->logisticTimingService->findByParams($cityName,$provinceName,$logistic->id);
        $this->assertNull($result);
    }
}
