| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?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']);
- if($batches->count()==0) $this->assertEmpty($batches);
- if ($batches->count()>0)$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
- }
- }
|