<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Tests\Unit\Services;

use Seka\Portal\Modul\Statistiky\Tests\TestCase;
use Seka\Portal\Modul\Statistiky\Services\Import\File;
use Seka\Portal\Modul\Statistiky\Services\Analyzators\XLSXHeader;
use Seka\Portal\Modul\Statistiky\Services\Import\ImportDataService;
use Seka\Portal\Modul\Statistiky\Repositories\ZaznamRepositoryContract;
use Seka\Portal\Modul\Statistiky\Services\Analyzators\XLSXDataAnalyzator;
use Seka\Portal\Modul\Statistiky\Services\Transformators\XLSXDataTransformator;

/**
 * Class XLSXImportDataServiceTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Services
 */
class XLSXImportDataServiceTest extends TestCase
{
    /**
     * @var \Seka\Portal\Modul\Statistiky\Services\Import\ImportDataService
     */
    private ImportDataService $service;

    /**
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function setUp(): void
    {
        parent::setUp();

        $pek = new \stdClass();
        $pek->id = 1;

        $pracoviskoRepository = $this->getMockBuilder('\App\Repositories\PracoviskoRepositoryContract')
            ->disableOriginalConstructor()
            ->allowMockingUnknownTypes()
            ->addMethods(['findByField'])
            ->getMock();
        $pracoviskoRepository->method('findByField')
            ->with(['field' => 'kod', 'value' => '0000'])
            ->willReturn($pek);

        $this->service = new ImportDataService(
            $this->app->make(ZaznamRepositoryContract::class),
            new XLSXDataAnalyzator(XLSXHeader::$header),
            $pracoviskoRepository,
            new XLSXDataTransformator()
        );
    }

    /**
     *
     */
    public function testInstance()
    {
        self::assertInstanceOf(ImportDataService::class, $this->service);
    }

    /**
     *
     */
    public function testExecute()
    {
        $this->service->execute(new File(__DIR__ . '/DENNY_VYPIS_KONTROL.xlsx'));
    }
}
