| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace Tests\Services\StationRuleBatchService;
- use App\Batch;
- use App\Order;
- use App\OrderCommodity;
- use App\Owner;
- use App\Services\BatchService;
- use App\Services\StationRuleBatchService;
- use App\StationRuleBatch;
- use App\StationTaskBatch;
- use Tests\TestCase;
- class GetBatches_shouldProcessTest extends TestCase
- {
- /** @var StationRuleBatchService $service */
- private $service;
- /** @var BatchService $batchService */
- private $batchService;
- private $data = [];
- private $amountOfInRule = 3;
- public function setUp(): void
- {
- parent::setUp();
- $this->service = app('StationRuleBatchService');
- $this->batchService = app('BatchService');
- $this->data['owner_target'] = factory(Owner::class)->create();
- $this->data['stationRuleBatch'] = factory(StationRuleBatch::class)
- ->create([
- 'owner_id' => $this->data['owner_target']['id'],
- ]);
- $this->data['batches'] = factory(Batch::class, $this->amountOfInRule)->create([
- 'owner_id' => $this->data['owner_target']['id'],
- ]);
- $this->data['stationTaskBatch']=collect();
- $this->data['order']=collect();
- foreach ($this->data['batches'] as $batch){
- $this->data['stationTaskBatch'] ->push(factory(StationTaskBatch::class)->create(['batch_id' => $batch['id'],]));
- $this->data['order']->push(factory(Order::class)->create(['batch_id' => $batch['id'],]));
- }
- $this->data['orderCommodities'] =collect();
- foreach ($this->data['order'] as $order){
- $this->data['orderCommodities']->push( factory(OrderCommodity::class)->create(['order_id'=>$order['id'],'location'=>'IDE100']));
- }
- }
- public function testFilteredOut()
- {
- $batches=$this->service->getBatches_shouldProcess($this->data['batches']);
- $this->assertEquals($this->amountOfInRule,$batches->count());
- }
- public function tearDown(): void
- {
- Owner::query()->whereIn('id',[
- $this->data['owner_target']['id'],
- ])->delete();
- OrderCommodity::query()->whereIn('id',data_get($this->data['orderCommodities'],'*.id'))->delete();
- StationTaskBatch::query()->whereIn('batch_id',data_get($this->data['batches'],'*.id'))->delete();
- Order::query()->whereIn('batch_id',data_get($this->data['batches'],'*.id'))->delete();
- StationRuleBatch::query()->where('id',$this->data['stationRuleBatch']['id'])->delete();
- Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id'))->delete();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|