AssignTasksTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Tests\Services\BatchService;
  3. use App\Order;
  4. use App\OrderCommodity;
  5. use App\Services\BatchService;
  6. use App\Station;
  7. use App\StationRuleBatch;
  8. use Tests\TestCase;
  9. use App\Batch;
  10. use App\Traits\TestMockSubServices;
  11. class AssignTasksTest extends TestCase
  12. {
  13. use TestMockSubServices;
  14. /** @var BatchService $service */
  15. public $service;
  16. private $data;
  17. private $batchAmount=2;
  18. private $orderAmount=4;
  19. private $orderCommodityAmount=8;
  20. function setUp(): void
  21. {
  22. parent::setUp();
  23. $this->service = app('BatchService');
  24. $this->data['batches']
  25. = factory(Batch::class, $this->batchAmount)
  26. ->create();
  27. $this->data['orders'] =
  28. factory(Order::class)
  29. ->createMany($this->makeArray($this->orderAmount,[
  30. 'status'=>'未处理',
  31. 'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
  32. ]));
  33. $this->data['orderCommodities'] =
  34. factory(OrderCommodity::class)
  35. ->createMany($this->makeArray($this->orderCommodityAmount,[
  36. 'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);}
  37. ]));
  38. $this->data['station_rule_batches']
  39. = factory(StationRuleBatch::class)
  40. ->createMany($this->makeArray($this->batchAmount,[
  41. 'owner_id' => function(){return $this->getTargetIdCirculately($this->data['batches'],'','owner_id');}
  42. ]));
  43. }
  44. public function testReturned()
  45. {
  46. $this->service->assignTasks($this->data['batches']);
  47. $this->data['batches']['0']->loadMissing('stationBatchTask.stationTask');
  48. $a=($this->data['batches']['0']['stationBatchTask']);
  49. dd($a);
  50. $this->assertEquals(data_get($this->data['batches'],'*.id'),$this->data['batches']);
  51. }
  52. function tearDown(): void
  53. {
  54. Batch::query()
  55. ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  56. ->delete();
  57. Order::query()
  58. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  59. ->delete();
  60. OrderCommodity::query()
  61. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  62. ->delete();
  63. StationRuleBatch::query()
  64. ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
  65. ->delete();
  66. parent::tearDown();
  67. }
  68. }