<?php

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

use Seka\Portal\Modul\Statistiky\Tests\TestCase;
use \App\Repositories\PracoviskoRepositoryContract;
use Seka\Portal\Modul\Statistiky\Services\ImportDataService;
use Seka\Portal\Modul\Statistiky\Services\ImportDataServiceContract;
use Seka\Portal\Modul\Statistiky\Repositories\ZaznamRepositoryContract;
use Seka\Portal\Modul\Statistiky\Services\Analyzators\DataAnalyzatorContract;
use Seka\Portal\Modul\Statistiky\Services\Transformators\DataTransformatorContract;

/**
 * Class ImportZaznamovCommandTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Console
 */
class ImportZaznamovCommandTest extends TestCase
{

    public function setUp(): void
    {
        parent::setUp();

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

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

        $this->app->bind(ImportDataServiceContract::class, function ($app) use ($pekRepo) {
            return new ImportDataService(
                $this->app->make(ZaznamRepositoryContract::class),
                $this->app->make(DataAnalyzatorContract::class),
                $pekRepo,
                $this->app->make(DataTransformatorContract::class)
            );
        });
    }

    /**
     *
     */
    public function testInstance()
    {
        $instance = new ImportZaznamovCommand();

        self::assertInstanceOf(ImportZaznamovCommand::class, $instance);
    }

    /**
     *
     */
    public function testHandleSuccess()
    {
        $this->artisan('statistiky:import ./../../../../Tests/Unit/Services/DENNY_VYPIS_KONTROL_VSETKY_PEK-20210610.csv')
            ->assertExitCode(1);
    }

    /**
     *
     */
    public function testHandleFailed()
    {
        $this->artisan('statistiky:import neexistujuci_subor.csv')
            ->assertExitCode(0);
    }
}
