<?php


namespace Tests\Services\StationCacheShelfGridService;
use App\MaterialBox;
use App\Services\StationCacheShelfGridService;
use App\Station;
use App\StationCacheShelfGrid;
use Tests\TestCase;


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

    protected function setup(): void
    {
        parent::setUp();
        $this->stationCacheShelfGridService = app(StationCacheShelfGridService::class);
        $this->data['station'] = factory(Station::class)->create();
        $this->data['materialBox'] = factory(MaterialBox::class)->create();
        $this->data['stationCacheShelfGrid'] = factory(StationCacheShelfGrid::class)->create();
    }

    public function test()
    {
        $this->stationCacheShelfGridService->processGrid($this->data['stationCacheShelfGrid'],$this->data['station'],$this->data['materialBox']);
        $grid = StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->first();
        $this->assertEquals($grid['id'],$this->data['stationCacheShelfGrid']['id']);
        $this->assertEquals($grid['station_id'],$this->data['station']['id']);
        $this->assertEquals($grid['material_box_id'],$this->data['materialBox']['id']);
    }
    protected function tearDown(): void
    {
        Station::query()->where('id',$this->data['station']['id'])->delete();
        MaterialBox::query()->where('id',$this->data['materialBox']['id'])->delete();
        StationCacheShelfGrid::query()->where('id',$this->data['stationCacheShelfGrid']['id'])->delete();
        parent::tearDown();
    }
}
