<?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\CSVHeader;
use Seka\Portal\Modul\Statistiky\Services\Import\ImportDataService;
use Seka\Portal\Modul\Statistiky\Repositories\ZaznamRepositoryContract;
use Seka\Portal\Modul\Statistiky\Services\Analyzators\CSVDataAnalyzator;
use Seka\Portal\Modul\Statistiky\Services\Transformators\CSVDataTransformator;

/**
 * Class CSVImportDataServiceTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Services
 */
class CSVImportDataServiceTest 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 CSVDataAnalyzator(CSVHeader::$header),
            $pracoviskoRepository,
            new CSVDataTransformator()
        );
    }

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

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