FindByParamsTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Tests\CacheService\LogisticTimingService\FindByParamsTest;
  3. use App\City;
  4. use App\Logistic;
  5. use App\Province;
  6. use App\Services\LogisticTimingService;
  7. use Illuminate\Foundation\Testing\RefreshDatabase;
  8. use Illuminate\Support\Facades\DB;
  9. use Tests\TestCase;
  10. class FindByParamsTest extends TestCase
  11. {
  12. /**
  13. * @var LogisticTimingService $logisticTimingService
  14. */
  15. public $logisticTimingService;
  16. public function setUp(): void
  17. {
  18. parent::setUp();
  19. $this->logisticTimingService = app(LogisticTimingService::class);
  20. // factory(Logistic::class)->create(['name'=>'新杰物流','code'=>'XJWL']);
  21. DB::insert('insert ignore into logistics (name,code) values(?, ?)',['新杰物流', 'XJWL']);
  22. $province = null;
  23. if(!Province::query()->where('name','like','江苏')->exists())
  24. $province = factory(Province::class)->create(['name'=>'江苏']);
  25. else
  26. $province = Province::query()->where('name','like','江苏')->first();
  27. if(!city::query()->where('name','like','南京'))
  28. factory(City::class)->create(['name'=>'南京', 'province_id'=>$province->id]);
  29. }
  30. /**
  31. * @test
  32. */
  33. public function findByParams()
  34. {
  35. $cityName = '江苏省';
  36. $provinceName = '南京市';
  37. $logistic = Logistic::query()->where('name','like','新杰物流'.'%')->first();
  38. $result = $this->logisticTimingService->findByParams($cityName,$provinceName,$logistic->id);
  39. $this->assertNull($result);
  40. }
  41. }