OwnerFeeDetailServiceTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Tests\Services\OwnerFeeDetailService;
  3. use App\Logistic;
  4. use App\Owner;
  5. use App\OwnerFeeDetail;
  6. use App\ProcessMethod;
  7. use App\Services\OwnerFeeDetailService;
  8. use App\Shop;
  9. use App\Unit;
  10. use App\UserOwnerGroup;
  11. use Illuminate\Support\Facades\DB;
  12. use Tests\TestCase;
  13. class OwnerFeeDetailServiceTest extends TestCase
  14. {
  15. /** @var OwnerFeeDetailService */
  16. public $service;
  17. public $data;
  18. protected function setUp(): void
  19. {
  20. parent::setUp();
  21. $this->service = app(OwnerFeeDetailService::class);
  22. $unit = factory(Unit::class)->create();
  23. $logistic = factory(Logistic::class)->create();
  24. $processMethod = factory(ProcessMethod::class)->create([
  25. "unit_id" => $unit->id,
  26. ]);
  27. $userOwnerGroup = factory(\App\UserOwnerGroup::class)->create();
  28. $owner = factory(\App\Owner::class)->create([
  29. "user_owner_group_id"=>$userOwnerGroup->id,
  30. ]);
  31. $shop = factory(Shop::class)->create([
  32. "owner_id" => $owner->id,
  33. ]);
  34. $this->data["userOwnerGroups"] = [$userOwnerGroup->toArray()];
  35. $this->data["owners"] = [$owner->toArray()];
  36. $this->data["shops"] = [$shop->toArray()];
  37. $this->data["units"] = [$unit->toArray()];
  38. $this->data["logistics"] = [$logistic->toArray()];
  39. $this->data["processMethods"] = [$processMethod->toArray()];
  40. $this->data["models"] = factory(OwnerFeeDetail::class,3)->create([
  41. "logistic_id" => $logistic->id, //物流ID
  42. "process_method_id" => $processMethod->id,//加工类型ID
  43. "owner_id" => $owner->id,
  44. "shop_id" => $shop->id
  45. ])->toArray();
  46. }
  47. /**
  48. * @group customer
  49. */
  50. public function testPaginate()
  51. {
  52. $models = $this->service->paginate(array("paginate"=>5));
  53. $this->assertGreaterThanOrEqual(3,count($models));
  54. $this->assertLessThanOrEqual(5,count($models));
  55. }
  56. /**
  57. * @group customer
  58. */
  59. public function testGetSql()
  60. {
  61. $ids = implode(",",array_column($this->data["models"],"id"));
  62. $sql = $this->service->getSql(["id"=>$ids]);
  63. $models = DB::select(DB::raw($sql));
  64. $this->assertCount(3,$models);
  65. }
  66. public function tearDown(): void
  67. {
  68. UserOwnerGroup::destroy(array_column($this->data["userOwnerGroups"],"id"));
  69. Owner::destroy(array_column($this->data["owners"],"id"));
  70. Shop::destroy(array_column($this->data["shops"],"id"));
  71. Unit::destroy(array_column($this->data["units"],"id"));
  72. Logistic::destroy(array_column($this->data["logistics"],"id"));
  73. ProcessMethod::destroy(array_column($this->data["processMethods"],"id"));
  74. OwnerFeeDetail::destroy(array_column($this->data["models"],"id"));
  75. parent::tearDown();
  76. }
  77. }