<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Tests\Unit\Entities\Zaznam\ValueObjects;

use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolSObratom;
use Seka\Portal\Modul\Statistiky\Tests\TestCase;

/**
 * Class PocetKontrolSObratomTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Entities\Zaznam\ValueObjects
 */
class PocetKontrolSObratomTest extends TestCase
{
    /**
     * @var \Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolSObratom
     */
    private PocetKontrolSObratom $obj;

    /**
     * @var float
     */
    private float $obrat;

    /**
     * @var int
     */
    private int $pocet;

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

        $this->pocet = 3;
        $this->obrat = 123.45;

        $this->obj = new PocetKontrolSObratom($this->obrat, $this->pocet);
    }

    /**
     *
     */
    public function testInstancie()
    {
        $obj = new PocetKontrolSObratom($this->obrat, $this->pocet);

        self::assertInstanceOf(PocetKontrolSObratom::class, $obj);
    }

    /**
     *
     */
    public function testPocet()
    {
        self::assertEquals($this->pocet, $this->obj->pocet());
    }

    /**
     *
     */
    public function testObrat()
    {
        self::assertEquals($this->obrat, $this->obj->obrat());
    }

    /**
     *
     */
    public function testNavysitPocetAObrat()
    {
        $navysitObrat = 100.0;
        $navysitPocet = 2;

        $test = new PocetKontrolSObratom($navysitObrat, $navysitPocet);
        $clone = (clone $this->obj)->navysitPocetAObrat($test);

        self::assertEquals($this->pocet + $navysitPocet, $clone->pocet());
        self::assertEquals($this->obrat + $navysitObrat, $clone->obrat());
    }

    /**
     *
     */
    public function testJsonSerialize()
    {
        self::assertJsonStringEqualsJsonString(
            '{"obrat":123.45,"pocet":3}',
            $this->obj->jsonSerialize()
        );
    }

    /**
     *
     */
    public function testToArray()
    {
        $arr = $this->obj->toArray();

        self::assertIsArray($arr);
        self::assertArrayHasKey('obrat', $arr);
        self::assertArrayHasKey('pocet', $arr);
    }
}
