<?php

namespace Tests\Feature\Services\CMMS;

use App\Services\CMMS\GetMachinesInfoListService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Mockery;
use Mockery\MockInterface;
use SoapClient;
use Tests\TestCase;

class GetMachinesInfoListTest extends TestCase
{
    use RefreshDatabase, WithFaker;
    /**
     * A basic feature test example.
     */
    public function test_data_returned_properly(): void
    {
        $data = [
            "Id" => $this->faker->numberBetween(1, 10),
            "PlakNumber" => $this->faker->numerify,
            "CarName" => $this->faker->name,
            "CarGroup" => $this->faker->name,
            "MachineCode" => $this->faker->numerify,
            "UnitName" => $this->faker->name,
            "Status" => $this->faker->numberBetween(1, 10),
            "UnitGroup" => $this->faker->name,
        ];
        $expected_response = [
            'vw_MachBankFull' => [
                [
                    "Id" => $data['Id'],
                    "PlakNumber" => $data['PlakNumber'],
                    "CarName" => $data['CarName'],
                    "CarGroup" => $data['CarGroup'],
                    "MachineCode" => $data['MachineCode'],
                    "UnitName" => $data['UnitName'],
                    "Status" => $data['Status'],
                    "UnitGroup" => $data['UnitGroup'],
                ],
                [
                    "Id" => $data['Id'],
                    "PlakNumber" => $data['PlakNumber'],
                    "CarName" => $data['CarName'],
                    "CarGroup" => $data['CarGroup'],
                    "MachineCode" => $data['MachineCode'],
                    "UnitName" => $data['UnitName'],
                    "Status" => $data['Status'],
                    "UnitGroup" => $data['UnitGroup'],
                ],
            ]
        ];

        $mockStdClass = Mockery::mock('stdClass');
        $mockResultObject = $mockStdClass->GetViewResult->NewDataSet->vw_MachBankFull;
        $mockResultObject->CarName = $data['CarName'];
        $mockResultObject->CarGroup = $data['CarGroup'];
        $mockResultObject->PlakNumber = $data['PlakNumber'];
        $mockResultObject->MachineCode = $data['MachineCode'];
        $mockResultObject->UnitName = $data['UnitName'];
        $mockResultObject->Status = $data['Status'];
        $mockResultObject->Id = $data['Id'];
        $mockResultObject->UnitGroup = $data['UnitGroup'];


        $this->mock(SoapClient::class, function (MockInterface $mock) use ($mockStdClass) {
            $mock->shouldReceive('GetView')
                ->andReturn($mockStdClass);
        });

        $service = new GetMachinesInfoListService();
        $actual_response = $service->run();

        $this->assertEquals($expected_response, $actual_response);
    }
}
