<?php

declare(strict_types=1);

namespace Qameta\Allure\Test\Model;

use PHPUnit\Framework\TestCase;
use Qameta\Allure\Model\TestResult;

use function json_decode;
use function json_encode;

/**
 * @covers \Qameta\Allure\Model\TestResult

 */
class TestResultTest extends TestCase
{
    public function testGetTitlePathReturnsEmptyArrayByDefault(): void
    {
        $testResult = new TestResult("e42e48d0-7a3f-4fba-8518-8e6ada04af1d");

        $titlePath = $testResult->getTitlePath();

        self::assertEquals([], $titlePath);
    }

    public function testSetTitlePathReturnsObjectItself(): void
    {
        $testResult = new TestResult("e42e48d0-7a3f-4fba-8518-8e6ada04af1d");

        $actual = $testResult->setTitlePath();

        self::assertSame($testResult, $actual);
    }

    public function testTitlePathCanBeSet(): void
    {
        $testResult = new TestResult("e42e48d0-7a3f-4fba-8518-8e6ada04af1d");
        $testResult->setTitlePath("foo", "bar", "baz");

        $titlePath = $testResult->getTitlePath();

        self::assertEquals(["foo", "bar", "baz"], $titlePath);
    }

    public function testTitlePathJsonSerialization(): void
    {
        $testResult = new TestResult("e42e48d0-7a3f-4fba-8518-8e6ada04af1d");
        $testResult->setTitlePath("foo", "bar", "baz");

        /** @psalm-var object{titlePath: list<string>} $decodedJson */
        $decodedJson = json_decode(json_encode($testResult));

        self::assertEquals(["foo", "bar", "baz"], $decodedJson->titlePath);
    }
}
