-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathStatusDetector.php
More file actions
72 lines (62 loc) · 2.12 KB
/
Copy pathStatusDetector.php
File metadata and controls
72 lines (62 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace Qameta\Allure\Codeception;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ExceptionWrapper;
use PHPUnit\Framework\SkippedTestError;
use Qameta\Allure\Model\Status;
use Qameta\Allure\Model\StatusDetails;
use Qameta\Allure\Setup\StatusDetectorInterface;
use Throwable;
/**
* @deprecated This class is not used anymore and will be removed in next major version.
* @psalm-suppress UnusedClass
*/
final class StatusDetector implements StatusDetectorInterface
{
public function __construct(
private StatusDetectorInterface $defaultStatusDetector,
) {
}
public function getStatus(Throwable $error): ?Status
{
return $this->getUnwrappedStatus(
$this->unwrapError($error),
);
}
private function getUnwrappedStatus(Throwable $error): Status
{
return match (true) {
$error instanceof SkippedTestError => Status::skipped(),
$error instanceof AssertionFailedError => Status::failed(),
default => Status::broken(),
};
}
public function getStatusDetails(Throwable $error): ?StatusDetails
{
$unwrappedError = $this->unwrapError($error);
$unwrappedStatus = $this->getUnwrappedStatus($unwrappedError);
return match (true) {
Status::skipped() === $unwrappedStatus,
Status::failed() === $unwrappedStatus => new StatusDetails(
message: $error->getMessage(),
trace: $error->getTraceAsString(),
),
default => $this->defaultStatusDetector->getStatusDetails($unwrappedError),
};
}
private function unwrapError(Throwable $error): Throwable
{
/** @psalm-suppress InternalMethod */
return $error instanceof ExceptionWrapper
? $error->getOriginalException() ?? $error
: $error;
}
private function buildMessage(Throwable $error): string
{
/** @psalm-suppress InternalMethod */
return $error instanceof AssertionFailedError
? $error->toString()
: $error->getMessage();
}
}