<?php

namespace Tests\Services\WarehouseService;

use App\OracleBasCustomer;
use App\Services\OracleBasCustomerService;
use App\Services\WarehouseService;
use App\Warehouse;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class GetWareHouseByCodeTest extends TestCase
{
    /** @var WarehouseService $service */
    private $service;
    private $data;

    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $this->service = app('WarehouseService');
        $warehouse = factory(Warehouse::class)->create();
        $basCustomer = factory(OracleBasCustomer::class)->make(['customerid'=>$warehouse->code,'descr_c'=>$warehouse->name,'customer_type'=>'OW']);
        $this->data['warehouse'] = $warehouse;
        $this->data['code'] = $warehouse->code;
        $this->data['basCustomer'] = $basCustomer;
        $this->mock(OracleBasCustomerService::class,function($mock)use($basCustomer){
            $mock->shouldReceive('first')->andReturn($basCustomer);
        });
    }

    /**
     * @test
     */
    public function getWareHouseByCodeTest()
    {
        $warehouse = $this->service->getWareHouseByCode($this->data['code']);
        $this->assertEquals($warehouse->toArray(),$this->data['warehouse']->toArray());
    }

    public function tearDown(): void
    {
        $this->data['warehouse']->delete();
        cache()->forget('WareHouse_'.$this->data['warehouse']->code);
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
