CreateByBatchesTest.php 2.2 KB

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