<?php

namespace Tests\Services\OwnerService;

use App\OracleBasCustomer;
use App\Owner;
use App\Services\OwnerService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetOwnerByCodeTest extends TestCase
{
    /** @var OwnerService $service */
    private $service;
    private $data = [];

    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        cache()->flush();
        $this->service = app('OwnerService');

        $owner  = factory(Owner::class)->create();
        $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner->code]);

        $this->data['basCustomer'] = $basCustomer;
        $this->data['owner'] = $owner;

        $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
            $mock->shouldReceive('first')->andReturn($basCustomer);
        });
    }

    /**
     * @test
     */
    public function getOwnerByCode()
    {
        $owner = $this->service->getOwnerByCode($this->data['owner']['code']);

        $this->assertEquals($owner->id,$this->data['owner']['id']);
        $this->assertEquals($owner->name,$this->data['owner']['name']);
        $this->assertEquals($owner->code,$this->data['owner']['code']);

    }


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