<?php


namespace Tests\Services\StationCacheShelfGridService;

use App\Services\StationCacheShelfGridService;
use App\StationCacheShelfGrid;
use App\Traits\TestMockSubServices;
use Tests\TestCase;

class CancelTaskTest extends TestCase
{
    use TestMockSubServices;
    /** @var StationCacheShelfGridService $stationCacheShelfGridService */
    protected $stationCacheShelfGridService;
    protected $data =[];

    protected function setup(): void
    {
        parent::setUp();
        $this->stationCacheShelfGridService = app(StationCacheShelfGridService::class);
        $this->data['grids'] = factory(StationCacheShelfGrid::class)->times(3)->create();

    }

    public function testCancelTask()
    {
        $this->stationCacheShelfGridService->cancelTask($this->data['grids']);
        $grids = StationCacheShelfGrid::query()->whereIn('id',data_get($this->data['grids'],'*.id'))->whereNull('material_box_id')->where('status',0)->count();
        $this->assertEquals($grids, count($this->data['grids']));
    }

    protected function tearDown(): void
    {
        StationCacheShelfGrid::query()->where('id',data_get($this->data['grids'],'*.id'))->delete();
        parent::tearDown();
    }

}
