GetBatches_shouldProcessTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. if($batches->count()==0) $this->assertEmpty($batches);
  48. if ($batches->count()>0)$this->assertEquals($this->amountOfInRule,$batches->count());
  49. }
  50. public function tearDown(): void
  51. {
  52. Owner::query()->whereIn('id',[
  53. $this->data['owner_target']['id'],
  54. ])->delete();
  55. OrderCommodity::query()->whereIn('id',data_get($this->data['orderCommodities'],'*.id'))->delete();
  56. StationTaskBatch::query()->whereIn('batch_id',data_get($this->data['batches'],'*.id'))->delete();
  57. Order::query()->whereIn('batch_id',data_get($this->data['batches'],'*.id'))->delete();
  58. StationRuleBatch::query()->where('id',$this->data['stationRuleBatch']['id'])->delete();
  59. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id'))->delete();
  60. parent::tearDown(); // TODO: Change the autogenerated stub
  61. }
  62. }