Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Model/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ final class TestResult extends ExecutionContext

protected ?string $fullName = null;

/**
* @var list<string>
*/
protected array $titlePath = [];

/**
* @var list<Label>
*/
Expand Down Expand Up @@ -79,6 +84,21 @@ public function setFullName(?string $fullName): self
return $this;
}

/**
* @return list<string>
*/
public function getTitlePath(): array
{
return $this->titlePath;
}

public function setTitlePath(string ...$items): self
{
$this->titlePath = array_values($items);

return $this;
}

/**
* @return list<Label>
*/
Expand Down
57 changes: 57 additions & 0 deletions test/Model/TestResultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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($actual, $testResult);
}

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

$titlePath = $testResult->getTitlePath();

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

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($decodedJson->titlePath, ["foo", "bar", "baz"]);
}
}
Loading