GetBatches_shouldProcessTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Tests\Services\StationRuleBatchService;
  3. use App\Batch;
  4. use App\Order;
  5. use App\OrderCommodity;
  6. use App\Owner;
  7. use App\Services\BatchService;
  8. use App\Services\StationRuleBatchService;
  9. use App\StationRuleBatch;
  10. use App\StationTaskBatch;
  11. use Tests\TestCase;
  12. class GetBatches_shouldProcessTest extends TestCase
  13. {
  14. /** @var StationRuleBatchService $service */
  15. private $service;
  16. /** @var BatchService $batchService */
  17. private $batchService;
  18. private $data = [];
  19. private $amountOfInRule = 3;
  20. public function setUp(): void
  21. {
  22. parent::setUp();
  23. $this->service = app('StationRuleBatchService');
  24. $this->batchService = app('BatchService');
  25. $this->data['owner_target'] = factory(Owner::class)->create();
  26. $this->data['stationRuleBatch'] = factory(StationRuleBatch::class)
  27. ->create([
  28. 'owner_id' => $this->data['owner_target']['id'],
  29. ]);
  30. $this->data['batches'] = factory(Batch::class, $this->amountOfInRule)->create([
  31. 'owner_id' => $this->data['owner_target']['id'],
  32. ]);
  33. $this->data['stationTaskBatch']=collect();
  34. $this->data['order']=collect();
  35. foreach ($this->data['batches'] as $batch){
  36. $this->data['stationTaskBatch'] ->push(factory(StationTaskBatch::class)->create(['batch_id' => $batch['id'],]));
  37. $this->data['order']->push(factory(Order::class)->create(['batch_id' => $batch['id'],]));
  38. }
  39. $this->data['orderCommodities'] =collect();
  40. foreach ($this->data['order'] as $order){
  41. $this->data['orderCommodities']->push( factory(OrderCommodity::class)->create(['order_id'=>$order['id'],'location'=>'IDE100']));
  42. }
  43. }
  44. public function testFilteredOut()
  45. {
  46. $batches=$this->service->getBatches_shouldProcess($this->data['batches']);
  47. $this->assertEquals($this->amountOfInRule,$batches->count());
  48. }
  49. public function tearDown(): void
  50. {
  51. Owner::query()->whereIn('id',[
  52. $this->data['owner_target']['id'],
  53. ])->delete();
  54. OrderCommodity::query()->whereIn('id',data_get($this->data['orderCommodities'],'*.id'))->delete();
  55. StationTaskBatch::query()->whereIn('batch_id',data_get($this->data['batches'],'*.id'))->delete();
  56. Order::query()->whereIn('batch_id',data_get($this->data['batches'],'*.id'))->delete();
  57. StationRuleBatch::query()->where('id',$this->data['stationRuleBatch']['id'])->delete();
  58. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id'))->delete();
  59. parent::tearDown(); // TODO: Change the autogenerated stub
  60. }
  61. }